Skip to content
Permalink
Browse files

Merge pull request #13 from ikedam/feature/JENKINS-22318_emptyInFileC…

…hoice

[JENKINS-22318] an empty choice in the file choice list
  • Loading branch information
ikedam committed May 15, 2015
2 parents 74176e3 + cb7d9e3 commit 7b9509d0ec41f6baf170336381f32fabd53db00e
@@ -45,10 +45,6 @@
/**
* Create a choice list from a list of files.
*/
/**
* @author yasuke
*
*/
public class FilenameChoiceListProvider extends ChoiceListProvider implements Serializable
{
private static final long serialVersionUID = 1329937323978223039L;
@@ -76,6 +72,26 @@ public String toString()
}
};

public enum EmptyChoiceType
{
None(Messages._FilenameChoiceListProvider_EmptyChoiceType_None()),
AtTop(Messages._FilenameChoiceListProvider_EmptyChoiceType_AtTop()),
AtEnd(Messages._FilenameChoiceListProvider_EmptyChoiceType_AtEnd());

private Localizable name;

private EmptyChoiceType(Localizable name)
{
this.name = name;
}

@Override
public String toString()
{
return name.toString();
}
}

private final String baseDirPath;

/**
@@ -168,22 +184,40 @@ public boolean isReverseOrder()
return reverseOrder;
}

private final EmptyChoiceType emptyChoiceType;

/**
* @return whether and where to put an empty choice.
*/
public EmptyChoiceType getEmptyChoiceType()
{
return emptyChoiceType;
}

/**
* The constructor called when a user posts a form.
*
* @param baseDirPath a path to the directory to scan.
* @param includePattern a pattern of file names to include to the list.
* @param excludePattern a pattern of file names to exclude from the list.
* @param scanType a type of files to list.
* @param emptyChoiceType whether and where to put an empty choice.
*/
@DataBoundConstructor
public FilenameChoiceListProvider(String baseDirPath, String includePattern, String excludePattern, ScanType scanType, boolean reverseOrder)
public FilenameChoiceListProvider(String baseDirPath, String includePattern, String excludePattern, ScanType scanType, boolean reverseOrder, EmptyChoiceType emptyChoiceType)
{
this.baseDirPath = StringUtils.trim(baseDirPath);
this.includePattern = StringUtils.trim(includePattern);
this.excludePattern = StringUtils.trim(excludePattern);
this.scanType = scanType;
this.reverseOrder = reverseOrder;
this.emptyChoiceType = emptyChoiceType;
}

@Deprecated
public FilenameChoiceListProvider(String baseDirPath, String includePattern, String excludePattern, ScanType scanType, boolean reverseOrder)
{
this(baseDirPath, includePattern, excludePattern, scanType, reverseOrder, EmptyChoiceType.None);
}

/**
@@ -215,7 +249,8 @@ public FilenameChoiceListProvider(String baseDirPath, String includePattern, Str
String includePattern,
String excludePattern,
ScanType scanType,
boolean reverseOrder
boolean reverseOrder,
EmptyChoiceType emptyChoiceType
)
{
if(baseDir == null || !baseDir.exists() || !baseDir.isDirectory())
@@ -285,9 +320,38 @@ public FilenameChoiceListProvider(String baseDirPath, String includePattern, Str
}
}

if(emptyChoiceType == null)
{
emptyChoiceType = EmptyChoiceType.None;
}

switch(emptyChoiceType)
{
case None:
break;
case AtTop:
ret.add(0, "");
break;
case AtEnd:
ret.add("");
break;
}

return ret;
}

@Deprecated
protected static List<String> getFileList(
File baseDir,
String includePattern,
String excludePattern,
ScanType scanType,
boolean reverseOrder
)
{
return getFileList(baseDir, includePattern, excludePattern, scanType, reverseOrder, EmptyChoiceType.None);
}

/**
* For backward compatibility.
*
@@ -323,7 +387,8 @@ public FilenameChoiceListProvider(String baseDirPath, String includePattern, Str
getIncludePattern(),
getExcludePattern(),
getScanType(),
isReverseOrder()
isReverseOrder(),
getEmptyChoiceType()
);
}

@@ -418,15 +483,17 @@ public FormValidation doTest(
@QueryParameter String includePattern,
@QueryParameter String excludePattern,
@QueryParameter ScanType scanType,
@QueryParameter boolean reverseOrder
@QueryParameter boolean reverseOrder,
@QueryParameter EmptyChoiceType emptyChoiceType
)
{
List<String> fileList = getFileList(
getBaseDir(baseDirPath),
includePattern,
excludePattern,
scanType,
reverseOrder
reverseOrder,
emptyChoiceType
);

if(fileList.isEmpty())
@@ -37,6 +37,9 @@ THE SOFTWARE.
<f:entry title="${%Reverse Order}" field="reverseOrder">
<f:checkbox />
</f:entry>
<f:entry title="${%Empty Choice}" field="emptyChoiceType">
<f:enum>${it}</f:enum>
</f:entry>
<f:validateButton
method="test"
title="${%List Files Now}"
@@ -0,0 +1,3 @@
<div>
Adds an empty choice to the specified place.
</div>
@@ -0,0 +1,3 @@
<div>
指定の場所に空の選択肢を追加します。
</div>
@@ -36,6 +36,9 @@ FilenameChoiceListProvider.ScanType.FileAndDirectory=File and Directory
FilenameChoiceListProvider.BaseDirPath.empty=Required
FilenameChoiceListProvider.BaseDirPath.notfound=Specified directory does not found.
FilenameChoiceListProvider.IncludePattern.empty=Required
FilenameChoiceListProvider.EmptyChoiceType.None=No emtpy choice
FilenameChoiceListProvider.EmptyChoiceType.AtTop=At the top of choices
FilenameChoiceListProvider.EmptyChoiceType.AtEnd=At the end of choices
AddEditedChoiceListProvider.WhenToAdd.Triggered=triggered
AddEditedChoiceListProvider.WhenToAdd.Completed=completed
AddEditedChoiceListProvider.WhenToAdd.CompletedStable=completed stable
@@ -53,6 +53,12 @@ FilenameChoiceListProvider.BaseDirPath.empty=\u5165\u529b\u3057\u3066\u304f\u306
FilenameChoiceListProvider.BaseDirPath.notfound=\u6307\u5b9a\u3055\u308c\u305f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093
# FilenameChoiceListProvider.IncludePattern.empty=入力してください
FilenameChoiceListProvider.IncludePattern.empty=\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044
# FilenameChoiceListProvider.EmptyChoiceType.None=なし
FilenameChoiceListProvider.EmptyChoiceType.None=\u306a\u3057
# FilenameChoiceListProvider.EmptyChoiceType.AtTop=選択肢の先頭
FilenameChoiceListProvider.EmptyChoiceType.AtTop=\u9078\u629e\u80a2\u306e\u5148\u982d
# FilenameChoiceListProvider.EmptyChoiceType.AtEnd=選択肢の末尾
FilenameChoiceListProvider.EmptyChoiceType.AtEnd=\u9078\u629e\u80a2\u306e\u672b\u5c3e
# AddEditedChoiceListProvider.WhenToAdd.Triggered=ビルド開始時
AddEditedChoiceListProvider.WhenToAdd.Triggered=\u30d3\u30eb\u30c9\u958b\u59cb\u6642
# AddEditedChoiceListProvider.WhenToAdd.Completed=ビルド完了時
@@ -24,7 +24,8 @@
package jp.ikedam.jenkins.plugins.extensible_choice_parameter;

import static org.junit.Assert.*;

import hudson.model.FreeStyleProject;
import hudson.model.ParametersDefinitionProperty;
import hudson.util.FormValidation;

import java.io.File;
@@ -70,6 +71,77 @@ public void testGetBaseDir()
return (FilenameChoiceListProvider.DescriptorImpl)Jenkins.getInstance().getDescriptor(FilenameChoiceListProvider.class);
}

@Test
public void testConfiguration() throws Exception
{
{
FreeStyleProject p = j.createFreeStyleProject();
FilenameChoiceListProvider expected = new FilenameChoiceListProvider(
"/some/path",
"**/*",
"**/*.java",
FilenameChoiceListProvider.ScanType.File,
false,
FilenameChoiceListProvider.EmptyChoiceType.None
);
p.addProperty(new ParametersDefinitionProperty(new ExtensibleChoiceParameterDefinition(
"Choice",
expected,
false,
""
)));
j.submit(j.createWebClient().getPage(p, "configure").getFormByName("config"));
j.assertEqualDataBoundBeans(
expected,
((ExtensibleChoiceParameterDefinition)p.getProperty(ParametersDefinitionProperty.class).getParameterDefinition("Choice")).getChoiceListProvider()
);
}
{
FreeStyleProject p = j.createFreeStyleProject();
FilenameChoiceListProvider expected = new FilenameChoiceListProvider(
"C:\\some\\path",
"**/*.java",
"**/*Test.java",
FilenameChoiceListProvider.ScanType.Directory,
true,
FilenameChoiceListProvider.EmptyChoiceType.AtTop
);
p.addProperty(new ParametersDefinitionProperty(new ExtensibleChoiceParameterDefinition(
"Choice",
expected,
false,
""
)));
j.submit(j.createWebClient().getPage(p, "configure").getFormByName("config"));
j.assertEqualDataBoundBeans(
expected,
((ExtensibleChoiceParameterDefinition)p.getProperty(ParametersDefinitionProperty.class).getParameterDefinition("Choice")).getChoiceListProvider()
);
}
{
FreeStyleProject p = j.createFreeStyleProject();
FilenameChoiceListProvider expected = new FilenameChoiceListProvider(
"relative/path",
"**/*",
"",
FilenameChoiceListProvider.ScanType.FileAndDirectory,
true,
FilenameChoiceListProvider.EmptyChoiceType.AtEnd
);
p.addProperty(new ParametersDefinitionProperty(new ExtensibleChoiceParameterDefinition(
"Choice",
expected,
false,
""
)));
j.submit(j.createWebClient().getPage(p, "configure").getFormByName("config"));
j.assertEqualDataBoundBeans(
expected,
((ExtensibleChoiceParameterDefinition)p.getProperty(ParametersDefinitionProperty.class).getParameterDefinition("Choice")).getChoiceListProvider()
);
}
}

@Test
public void testDescriptor_doCheckBaseDirPath() throws IOException
{

0 comments on commit 7b9509d

Please sign in to comment.
You can’t perform that action at this time.