Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extra comma error in list of projects #111

Merged
merged 4 commits into from
Jan 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,10 @@ public FormValidation doCheckProjects(@AncestorInPath Job<?,?> project, @QueryPa
boolean hasProjects = false;
while(tokens.hasMoreTokens()) {
String projectName = tokens.nextToken().trim();
if (StringUtils.isNotBlank(projectName)) {
if (StringUtils.isBlank(projectName)) {
return FormValidation.error("Blank project name in the list");
}

Item item = Jenkins.getInstance().getItem(projectName,project,Item.class); // only works after version 1.410
if(item==null){
Item nearest = Items.findNearest(Job.class, projectName, Jenkins.getInstance());
Expand All @@ -667,7 +670,6 @@ public FormValidation doCheckProjects(@AncestorInPath Job<?,?> project, @QueryPa

hasProjects = true;
}
}
if (!hasProjects) {
return FormValidation.error(Messages.BuildTrigger_NoProjectSpecified());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static String readFileToString(FilePath f, String encoding) throws IOExce
}

/**
* {@link read VirtualFile
* {@link} read VirtualFile
*
* @param f file to read
* @return read string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import hudson.security.AuthorizationMatrixProperty;
import hudson.security.Permission;
import hudson.security.ProjectMatrixAuthorizationStrategy;
import hudson.util.FormValidation;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
Expand Down Expand Up @@ -307,4 +308,39 @@ public void testGetProjectListTriggered() throws Exception {

}

@Test
public void testBlankConfig() throws Exception {
Project<?, ?> masterProject = r.createFreeStyleProject("project");

FormValidation form = r.jenkins.getDescriptorByType(BuildTriggerConfig.DescriptorImpl.class).doCheckProjects(masterProject, "");

assertEquals(FormValidation.Kind.ERROR, form.kind);
}

@Test
public void testNonExistedProject() throws Exception {
Project<?, ?> masterProject = r.createFreeStyleProject("project");

FormValidation form = r.jenkins.getDescriptorByType(BuildTriggerConfig.DescriptorImpl.class).doCheckProjects(masterProject, "nonExistedProject");

assertEquals(FormValidation.Kind.ERROR, form.kind);
}

@Test
public void testValidConfig() throws Exception {
Project<?, ?> masterProject = r.createFreeStyleProject("project");

FormValidation form = r.jenkins.getDescriptorByType(BuildTriggerConfig.DescriptorImpl.class).doCheckProjects(masterProject, "project");

assertEquals(FormValidation.Kind.OK, form.kind);
}

@Test
public void testBlankProjectNameInConfig() throws Exception {
Project<?, ?> masterProject = r.createFreeStyleProject("project");

FormValidation form = r.jenkins.getDescriptorByType(BuildTriggerConfig.DescriptorImpl.class).doCheckProjects(masterProject, "project, ");

assertEquals(FormValidation.Kind.ERROR, form.kind);
}
}