-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
b19ae98
commit ed6e12e
Showing
17 changed files
with
388 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
truffle/src/main/java/org/jruby/truffle/options/BooleanOptionDescription.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.options; | ||
|
||
public class BooleanOptionDescription extends OptionDescription { | ||
|
||
private final boolean defaultValue; | ||
|
||
public BooleanOptionDescription(String name, String description, boolean defaultValue) { | ||
super(name, description); | ||
this.defaultValue = defaultValue; | ||
} | ||
|
||
@Override | ||
public Object getDefaultValue() { | ||
return defaultValue; | ||
} | ||
|
||
@Override | ||
public Object checkValue(Object value) { | ||
if (value instanceof Boolean) { | ||
return value; | ||
} else if (value instanceof String) { | ||
switch ((String) value) { | ||
case "true": | ||
return true; | ||
case "false": | ||
return false; | ||
default: | ||
throw new OptionTypeException(); | ||
} | ||
} else { | ||
throw new OptionTypeException(); | ||
} | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
truffle/src/main/java/org/jruby/truffle/options/NewOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.options; | ||
|
||
// This file would be automatically generated from the list of options in the text file. | ||
|
||
public class NewOptions { | ||
|
||
public final String[] ARGUMENTS; | ||
|
||
public final boolean EXCEPTIONS_PRINT_JAVA; | ||
|
||
NewOptions(OptionsBuilder builder) { | ||
ARGUMENTS = builder.getOrDefault(OptionsCatalogue.ARGUMENTS); | ||
EXCEPTIONS_PRINT_JAVA = builder.getOrDefault(OptionsCatalogue.EXCEPTIONS_PRINT_JAVA); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
truffle/src/main/java/org/jruby/truffle/options/OptionDescription.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.options; | ||
|
||
public abstract class OptionDescription { | ||
|
||
private final String name; | ||
private final String description; | ||
|
||
public OptionDescription(String name, String description) { | ||
this.name = name; | ||
this.description = description; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public abstract Object getDefaultValue(); | ||
|
||
public abstract Object checkValue(Object value); | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
truffle/src/main/java/org/jruby/truffle/options/OptionTypeException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.options; | ||
|
||
public class OptionTypeException extends UnsupportedOperationException { | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
truffle/src/main/java/org/jruby/truffle/options/OptionsBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.options; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
public class OptionsBuilder { | ||
|
||
private final String LEGACY_PREFIX = "jruby.truffle."; | ||
|
||
private final Map<OptionDescription, Object> options = new HashMap<>(); | ||
|
||
public void set(Properties properties) { | ||
for (Map.Entry<Object, Object> property : properties.entrySet()) { | ||
final String name = (String) property.getKey(); | ||
|
||
if (name.startsWith(LEGACY_PREFIX)) { | ||
set(name.substring(LEGACY_PREFIX.length()), property.getValue()); | ||
} | ||
} | ||
} | ||
|
||
public void set(Map<String, Object> properties) { | ||
for (Map.Entry<String, Object> property : properties.entrySet()) { | ||
set(property.getKey(), property.getValue()); | ||
} | ||
} | ||
|
||
private void set(String name, Object value) { | ||
final OptionDescription description = OptionsCatalogue.fromName(name); | ||
|
||
if (description == null) { | ||
//throw new UnsupportedOperationException(name); | ||
|
||
// Don't throw for now - not all the options are transalted across | ||
return; | ||
} | ||
|
||
options.put(description, description.checkValue(value)); | ||
} | ||
|
||
public NewOptions build() { | ||
return new NewOptions(this); | ||
} | ||
|
||
<T> T getOrDefault(OptionDescription description) { | ||
Object value = options.get(description); | ||
|
||
if (value == null) { | ||
value = description.getDefaultValue(); | ||
} | ||
|
||
return (T) value; | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
truffle/src/main/java/org/jruby/truffle/options/OptionsCatalogue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.options; | ||
|
||
// This file would be automatically generated from the list of options in the text file. | ||
|
||
public class OptionsCatalogue { | ||
|
||
public static final OptionDescription ARGUMENTS = new StringArrayOptionDescription("arguments", "Foo bar baz", new String[0]); | ||
|
||
public static final OptionDescription EXCEPTIONS_PRINT_JAVA = new BooleanOptionDescription("exceptions.print_java", "Foo baz bar", false); | ||
|
||
public static OptionDescription fromName(String name) { | ||
switch (name) { | ||
case "arguments": | ||
return ARGUMENTS; | ||
case "exceptions.print_java": | ||
return EXCEPTIONS_PRINT_JAVA; | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
} |
131 changes: 131 additions & 0 deletions
131
truffle/src/main/java/org/jruby/truffle/options/StringArrayOptionDescription.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.options; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class StringArrayOptionDescription extends OptionDescription { | ||
|
||
private final String[] defaultValue; | ||
|
||
public StringArrayOptionDescription(String name, String description, String[] defaultValue) { | ||
super(name, description); | ||
this.defaultValue = defaultValue; | ||
} | ||
|
||
@Override | ||
public Object getDefaultValue() { | ||
return defaultValue.clone(); | ||
} | ||
|
||
@Override | ||
public Object checkValue(Object value) { | ||
if (value instanceof String[]) { | ||
return value; | ||
} else if (value instanceof String) { | ||
return parseStringArray((String) value); | ||
} else { | ||
throw new OptionTypeException(); | ||
} | ||
} | ||
|
||
// Allows input such as [foo, "bar", 'baz']. Doesn't support escape sequences. | ||
|
||
private String[] parseStringArray(String string) { | ||
final List<String> values = new ArrayList<>(); | ||
|
||
final int start = 0; | ||
final int startOfString = 1; | ||
final int endOfString = 2; | ||
final int endOfArray = 3; | ||
|
||
int n = 0; | ||
int state = start; | ||
boolean array = false; | ||
|
||
while (n < string.length()) { | ||
while (n < string.length() && Character.isWhitespace(string.charAt(n))) { | ||
n++; | ||
} | ||
|
||
if (n == string.length() && array && state != start && state != endOfArray) { | ||
throw new OptionTypeException(); | ||
} | ||
|
||
switch (state) { | ||
case start: | ||
if (string.charAt(n) == '[') { | ||
n++; | ||
array = true; | ||
state = startOfString; | ||
} else { | ||
array = false; | ||
state = startOfString; | ||
} | ||
break; | ||
|
||
case startOfString: | ||
final int startN; | ||
final int endN; | ||
if (string.charAt(n) == '"' || string.charAt(n) == '\'') { | ||
final char quote = string.charAt(n); | ||
|
||
n++; | ||
startN = n; | ||
|
||
while (n < string.length() && string.charAt(n) != quote) { | ||
n++; | ||
} | ||
|
||
endN = n; | ||
|
||
if (string.charAt(n) == quote){ | ||
n++; | ||
} else { | ||
throw new OptionTypeException(); | ||
} | ||
|
||
state = endOfString; | ||
} else { | ||
startN = n; | ||
|
||
while (n < string.length() && string.charAt(n) != ',') { | ||
n++; | ||
} | ||
|
||
endN = n; | ||
|
||
state = endOfString; | ||
} | ||
values.add(string.substring(startN, endN)); | ||
break; | ||
|
||
case endOfString: | ||
if (string.charAt(n) == ',') { | ||
n++; | ||
state = startOfString; | ||
} else if (array && string.charAt(n) == ']') { | ||
n++; | ||
state = endOfArray; | ||
} else { | ||
throw new OptionTypeException(); | ||
} | ||
break; | ||
|
||
case endOfArray: | ||
break; | ||
} | ||
} | ||
|
||
return values.toArray(new String[values.size()]); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
truffle/src/main/java/org/jruby/truffle/options/UnknownOptionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.options; | ||
|
||
public class UnknownOptionException extends UnsupportedOperationException { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ARGUMENTS arguments String[] [] "Foo bar baz" | ||
EXCEPTIONS_PRINT_JAVA exceptions.print_java boolean false "Foo baz bar" |