Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-28041] Incorporated changes from feedback by Oleg
  • Loading branch information
pjanouse committed May 19, 2015
1 parent 3cc5162 commit 9d284a5
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
10 changes: 8 additions & 2 deletions core/src/main/java/hudson/cli/DeleteJobCommand.java
Expand Up @@ -51,15 +51,21 @@ public String getShortDescription() {
protected int run() throws Exception {

boolean errorOccurred = false;
final Jenkins jenkins = Jenkins.getInstance();

HashSet<String> hs = new HashSet<String>();
if (jenkins == null) {
stderr.println("The Jenkins instance has not been started, or was already shut down!");
return -1;
}

final HashSet<String> hs = new HashSet<String>();
hs.addAll(jobs);

for (String job_s: hs) {
AbstractItem job = null;

try {
job = (AbstractItem) Jenkins.getInstance().getItemByFullName(job_s);
job = (AbstractItem) jenkins.getItemByFullName(job_s);

if(job == null) {
stderr.format("No such job '%s'\n", job_s);
Expand Down
12 changes: 9 additions & 3 deletions core/src/main/java/hudson/cli/DeleteNodeCommand.java
Expand Up @@ -52,15 +52,21 @@ public String getShortDescription() {
protected int run() throws Exception {

boolean errorOccurred = false;
final Jenkins jenkins = Jenkins.getInstance();

HashSet<String> hs = new HashSet<String>();
if (jenkins == null) {
stderr.println("The Jenkins instance has not been started, or was already shut down!");
return -1;
}

final HashSet<String> hs = new HashSet<String>();
hs.addAll(nodes);

for (String node_s : hs) {
Node node = null;

try {
node = Jenkins.getInstance().getNode(node_s);
node = jenkins.getNode(node_s);

if(node == null) {
stderr.format("No such node '%s'\n", node_s);
Expand All @@ -76,7 +82,7 @@ protected int run() throws Exception {
continue;
}

Jenkins.getInstance().removeNode(node);
jenkins.removeNode(node);
} catch (Exception e) {
stderr.format("Unexpected exception occurred during deletion of node '%s': %s\n",
node == null ? "(null)" : node.toComputer().getName(),
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/cli/DeleteViewCommand.java
Expand Up @@ -55,7 +55,7 @@ protected int run() throws Exception {
boolean errorOccurred = false;

// Remove duplicates
HashSet<String> hs = new HashSet<String>();
final HashSet<String> hs = new HashSet<String>();
hs.addAll(views);

ViewOptionHandler voh = new ViewOptionHandler(null, null, null);
Expand Down
21 changes: 19 additions & 2 deletions core/src/main/java/hudson/cli/handlers/ViewOptionHandler.java
Expand Up @@ -38,6 +38,8 @@
import org.kohsuke.args4j.spi.Parameters;
import org.kohsuke.args4j.spi.Setter;

import javax.annotation.CheckForNull;

/**
* Refers to {@link View} by its name.
*
Expand Down Expand Up @@ -73,10 +75,25 @@ public int parseArguments(Parameters params) throws CmdLineException {
return 1;
}

public View getView(String name) throws CmdLineException {
/**
*
* Gets a view by its name
*
* @param name A view name
* @return The {@link View} instance. Null if {@link Jenkins#getInstance()} returns null.
* @throws CmdLineException
* If view isn't found or an un-expected error occurred
* @since TODO
*/
@CheckForNull
public View getView(final String name) throws CmdLineException {

View view = null;
ViewGroup group = Jenkins.getInstance();
View view = null;

if (group == null)
throw new CmdLineException(owner,
"The Jenkins instance has not been started, or was already shut down!");

final StringTokenizer tok = new StringTokenizer(name, "/");
while(tok.hasMoreTokens()) {
Expand Down
2 changes: 1 addition & 1 deletion test/src/test/java/hudson/cli/DeleteViewCommandTest.java
Expand Up @@ -45,7 +45,7 @@
import org.jvnet.hudson.test.JenkinsRule;

/**
* @author ??, pjanouse
* @author ogondza, pjanouse
*/
public class DeleteViewCommandTest {

Expand Down

0 comments on commit 9d284a5

Please sign in to comment.