-
-
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.
- Loading branch information
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; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.