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

OptionHandler's getMetaVariable fails when used with ResourceBundle #109

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions args4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<directory>test</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</testResource>
</testResources>
Expand Down
4 changes: 3 additions & 1 deletion args4j/src/org/kohsuke/args4j/CmdLineParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,9 @@ private String createDefaultValuePart(OptionHandler handler) {
}

private String localize(String s, ResourceBundle rb) {
if(rb!=null) return rb.getString(s);
if(rb!=null && rb.containsKey(s)) {
return rb.getString(s);
}
return s;
}

Expand Down
6 changes: 2 additions & 4 deletions args4j/src/org/kohsuke/args4j/spi/OptionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ public String getMetaVariable(ResourceBundle rb) {
token = getDefaultMetaVariable();
if(token==null) return null;

if(rb!=null) {
String localized = rb.getString(token);
if(localized!=null)
token = localized;
if(rb!=null && rb.containsKey(token)) {
token = rb.getString(token);
}

return token;
Expand Down
20 changes: 20 additions & 0 deletions args4j/test/org/kohsuke/args4j/ArgumentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import junit.framework.TestCase;

import java.io.File;
import java.io.StringWriter;
import java.util.List;
import java.util.ResourceBundle;

public class ArgumentTest extends TestCase {
protected static class MultiValueHolder {
Expand All @@ -20,6 +23,14 @@ protected static class BooleanValueHolder {
public boolean b;
}

protected static class I18NValueHolder {
@Argument(usage = "FILE2READ", required = true)
public File b;

@Option(name = "-a", usage = "1 2 3")
public String opt;
}

public void testMultiValue() throws Exception {
MultiValueHolder holder = new MultiValueHolder();
CmdLineParser parser = new CmdLineParser(holder);
Expand Down Expand Up @@ -64,4 +75,13 @@ public void testIllegalBoolean() throws Exception {
}
fail("expected " + CmdLineException.class);
}

public void testI18N() {
I18NValueHolder holder = new I18NValueHolder();
CmdLineParser parser = new CmdLineParser(holder);
StringWriter sw = new StringWriter();
ResourceBundle rb = ResourceBundle.getBundle("org/kohsuke/args4j/ArgumentTestI18N");
parser.printUsage(sw, rb);
assertTrue(sw.toString()!=null);
}
}
1 change: 1 addition & 0 deletions args4j/test/org/kohsuke/args4j/ArgumentTestI18N.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FILE2READ=File to read