properties, JSONObject props) throws IOException {
- for (Object p : props.keySet()) {
- String key = p.toString();
-
- if (key.equals("@files")) {
- JSONArray propertyFiles = props.getJSONArray(key);
- for (int i = 0; i < propertyFiles.length(); i++) {
- String propertyFile = propertyFiles.getString(i);
- Path propertyFilePath = path == null ? Paths.get(propertyFile) : path.resolve(propertyFile);
-
- if (!propertyFilePath.toFile().exists()) {
- throw new IllegalArgumentException(
- "can't resolve property file " + propertyFilePath.toAbsolutePath() + "." +
- " Not found." +
- (path == null ?
- " Note that parsing from mere inputstream resolve files " +
- "relative to current directory." :
- ""));
- }
-
- try (InputStreamReader reader = new InputStreamReader(Files.newInputStream(propertyFilePath))) {
- loadJsonProperties(propertyFilePath.getParent(), properties, new JSONObject(new JSONTokener(reader)));
- }
- }
- } else {
- properties.put(key, props.getString(key));
- }
- }
- }
- }
-
- private final Generator generator = new Generator();
- private final Parser parser = new Parser();
-
- public void generate(ModuleDescriptor md, Writer w) throws IOException {
- generator.generate(md, w);
- }
-
- public ModuleDescriptor parse(InputStream inputStream) throws IOException {
- return parser.parse(inputStream);
- }
-
- public ModuleDescriptor parse(Path path) throws IOException {
- return parser.parse(path);
- }
-
- @Override
- public String getDefaultFileName() {
- return "md.restx.json";
- }
-}
diff --git a/restx-build/src/main/java/restx/build/org/json/JSONArray.java b/restx-build/src/main/java/restx/build/org/json/JSONArray.java
deleted file mode 100644
index 038b12422..000000000
--- a/restx-build/src/main/java/restx/build/org/json/JSONArray.java
+++ /dev/null
@@ -1,948 +0,0 @@
-package restx.build.org.json;
-
-/*
- Copyright (c) 2002 JSON.org
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
-
- The Software shall be used for Good, not Evil.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- */
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.lang.reflect.Array;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * A JSONArray is an ordered sequence of values. Its external text form is a
- * string wrapped in square brackets with commas separating the values. The
- * internal form is an object having get
and opt
- * methods for accessing the values by index, and put
methods for
- * adding or replacing values. The values can be any of these types:
- * Boolean
, JSONArray
, JSONObject
,
- * Number
, String
, or the
- * JSONObject.NULL object
.
- *
- * The constructor can convert a JSON text into a Java object. The
- * toString
method converts to JSON text.
- *
- * A get
method returns a value if one can be found, and throws an
- * exception if one cannot be found. An opt
method returns a
- * default value instead of throwing an exception, and so is useful for
- * obtaining optional values.
- *
- * The generic get()
and opt()
methods return an
- * object which you can cast or query for type. There are also typed
- * get
and opt
methods that do type checking and type
- * coercion for you.
- *
- * The texts produced by the toString
methods strictly conform to
- * JSON syntax rules. The constructors are more forgiving in the texts they will
- * accept:
- *
- * - An extra
,
(comma) may appear just
- * before the closing bracket.
- * - The
null
value will be inserted when there is ,
- * (comma) elision.
- * - Strings may be quoted with
'
(single
- * quote).
- * - Strings do not need to be quoted at all if they do not begin with a quote
- * or single quote, and if they do not contain leading or trailing spaces, and
- * if they do not contain any of these characters:
- *
{ } [ ] / \ : , = ; #
and if they do not look like numbers and
- * if they are not the reserved words true
, false
, or
- * null
.
- * - Values can be separated by
;
(semicolon) as
- * well as by ,
(comma).
- *
- *
- * @author JSON.org
- * @version 2012-11-13
- */
-@SuppressWarnings("unchecked")
-public class JSONArray {
-
- /**
- * The arrayList where the JSONArray's properties are kept.
- */
- private final ArrayList myArrayList;
-
- /**
- * Construct an empty JSONArray.
- */
- public JSONArray() {
- this.myArrayList = new ArrayList();
- }
-
- /**
- * Construct a JSONArray from a JSONTokener.
- *
- * @param x
- * A JSONTokener
- * @throws JSONException
- * If there is a syntax error.
- */
- public JSONArray(JSONTokener x) throws JSONException {
- this();
- if (x.nextClean() != '[') {
- throw x.syntaxError("A JSONArray text must start with '['");
- }
- if (x.nextClean() != ']') {
- x.back();
- for (;;) {
- if (x.nextClean() == ',') {
- x.back();
- this.myArrayList.add(JSONObject.NULL);
- } else {
- x.back();
- this.myArrayList.add(x.nextValue());
- }
- switch (x.nextClean()) {
- case ';':
- case ',':
- if (x.nextClean() == ']') {
- return;
- }
- x.back();
- break;
- case ']':
- return;
- default:
- throw x.syntaxError("Expected a ',' or ']'");
- }
- }
- }
- }
-
- /**
- * Construct a JSONArray from a source JSON text.
- *
- * @param source
- * A string that begins with [
(left
- * bracket) and ends with ]
- * (right bracket).
- * @throws JSONException
- * If there is a syntax error.
- */
- public JSONArray(String source) throws JSONException {
- this(new JSONTokener(source));
- }
-
- /**
- * Construct a JSONArray from a Collection.
- *
- * @param collection
- * A Collection.
- */
- public JSONArray(Collection collection) {
- this.myArrayList = new ArrayList();
- if (collection != null) {
- Iterator iter = collection.iterator();
- while (iter.hasNext()) {
- this.myArrayList.add(JSONObject.wrap(iter.next()));
- }
- }
- }
-
- /**
- * Construct a JSONArray from an array
- *
- * @throws JSONException
- * If not an array.
- */
- public JSONArray(Object array) throws JSONException {
- this();
- if (array.getClass().isArray()) {
- int length = Array.getLength(array);
- for (int i = 0; i < length; i += 1) {
- this.put(JSONObject.wrap(Array.get(array, i)));
- }
- } else {
- throw new JSONException(
- "JSONArray initial value should be a string or collection or array.");
- }
- }
-
- /**
- * Get the object value associated with an index.
- *
- * @param index
- * The index must be between 0 and length() - 1.
- * @return An object value.
- * @throws JSONException
- * If there is no value for the index.
- */
- public Object get(int index) throws JSONException {
- Object object = this.opt(index);
- if (object == null) {
- throw new JSONException("JSONArray[" + index + "] not found.");
- }
- return object;
- }
-
- /**
- * Get the boolean value associated with an index. The string values "true"
- * and "false" are converted to boolean.
- *
- * @param index
- * The index must be between 0 and length() - 1.
- * @return The truth.
- * @throws JSONException
- * If there is no value for the index or if the value is not
- * convertible to boolean.
- */
- public boolean getBoolean(int index) throws JSONException {
- Object object = this.get(index);
- if (object.equals(Boolean.FALSE)
- || (object instanceof String && ((String) object)
- .equalsIgnoreCase("false"))) {
- return false;
- } else if (object.equals(Boolean.TRUE)
- || (object instanceof String && ((String) object)
- .equalsIgnoreCase("true"))) {
- return true;
- }
- throw new JSONException("JSONArray[" + index + "] is not a boolean.");
- }
-
- /**
- * Get the double value associated with an index.
- *
- * @param index
- * The index must be between 0 and length() - 1.
- * @return The value.
- * @throws JSONException
- * If the key is not found or if the value cannot be converted
- * to a number.
- */
- public double getDouble(int index) throws JSONException {
- Object object = this.get(index);
- try {
- return object instanceof Number ? ((Number) object).doubleValue()
- : Double.parseDouble((String) object);
- } catch (Exception e) {
- throw new JSONException("JSONArray[" + index + "] is not a number.");
- }
- }
-
- /**
- * Get the int value associated with an index.
- *
- * @param index
- * The index must be between 0 and length() - 1.
- * @return The value.
- * @throws JSONException
- * If the key is not found or if the value is not a number.
- */
- public int getInt(int index) throws JSONException {
- Object object = this.get(index);
- try {
- return object instanceof Number ? ((Number) object).intValue()
- : Integer.parseInt((String) object);
- } catch (Exception e) {
- throw new JSONException("JSONArray[" + index + "] is not a number.");
- }
- }
-
- /**
- * Get the JSONArray associated with an index.
- *
- * @param index
- * The index must be between 0 and length() - 1.
- * @return A JSONArray value.
- * @throws JSONException
- * If there is no value for the index. or if the value is not a
- * JSONArray
- */
- public JSONArray getJSONArray(int index) throws JSONException {
- Object object = this.get(index);
- if (object instanceof JSONArray) {
- return (JSONArray) object;
- }
- throw new JSONException("JSONArray[" + index + "] is not a JSONArray.");
- }
-
- /**
- * Get the JSONObject associated with an index.
- *
- * @param index
- * subscript
- * @return A JSONObject value.
- * @throws JSONException
- * If there is no value for the index or if the value is not a
- * JSONObject
- */
- public JSONObject getJSONObject(int index) throws JSONException {
- Object object = this.get(index);
- if (object instanceof JSONObject) {
- return (JSONObject) object;
- }
- throw new JSONException("JSONArray[" + index + "] is not a JSONObject.");
- }
-
- /**
- * Get the long value associated with an index.
- *
- * @param index
- * The index must be between 0 and length() - 1.
- * @return The value.
- * @throws JSONException
- * If the key is not found or if the value cannot be converted
- * to a number.
- */
- public long getLong(int index) throws JSONException {
- Object object = this.get(index);
- try {
- return object instanceof Number ? ((Number) object).longValue()
- : Long.parseLong((String) object);
- } catch (Exception e) {
- throw new JSONException("JSONArray[" + index + "] is not a number.");
- }
- }
-
- /**
- * Get the string associated with an index.
- *
- * @param index
- * The index must be between 0 and length() - 1.
- * @return A string value.
- * @throws JSONException
- * If there is no string value for the index.
- */
- public String getString(int index) throws JSONException {
- Object object = this.get(index);
- if (object instanceof String) {
- return (String) object;
- }
- throw new JSONException("JSONArray[" + index + "] not a string.");
- }
-
- /**
- * Determine if the value is null.
- *
- * @param index
- * The index must be between 0 and length() - 1.
- * @return true if the value at the index is null, or if there is no value.
- */
- public boolean isNull(int index) {
- return JSONObject.NULL.equals(this.opt(index));
- }
-
- /**
- * Make a string from the contents of this JSONArray. The
- * separator
string is inserted between each element. Warning:
- * This method assumes that the data structure is acyclical.
- *
- * @param separator
- * A string that will be inserted between the elements.
- * @return a string.
- * @throws JSONException
- * If the array contains an invalid number.
- */
- public String join(String separator) throws JSONException {
- int len = this.length();
- StringBuffer sb = new StringBuffer();
-
- for (int i = 0; i < len; i += 1) {
- if (i > 0) {
- sb.append(separator);
- }
- sb.append(JSONObject.valueToString(this.myArrayList.get(i)));
- }
- return sb.toString();
- }
-
- /**
- * Get the number of elements in the JSONArray, included nulls.
- *
- * @return The length (or size).
- */
- public int length() {
- return this.myArrayList.size();
- }
-
- /**
- * Get the optional object value associated with an index.
- *
- * @param index
- * The index must be between 0 and length() - 1.
- * @return An object value, or null if there is no object at that index.
- */
- public Object opt(int index) {
- return (index < 0 || index >= this.length()) ? null : this.myArrayList
- .get(index);
- }
-
- /**
- * Get the optional boolean value associated with an index. It returns false
- * if there is no value at that index, or if the value is not Boolean.TRUE
- * or the String "true".
- *
- * @param index
- * The index must be between 0 and length() - 1.
- * @return The truth.
- */
- public boolean optBoolean(int index) {
- return this.optBoolean(index, false);
- }
-
- /**
- * Get the optional boolean value associated with an index. It returns the
- * defaultValue if there is no value at that index or if it is not a Boolean
- * or the String "true" or "false" (case insensitive).
- *
- * @param index
- * The index must be between 0 and length() - 1.
- * @param defaultValue
- * A boolean default.
- * @return The truth.
- */
- public boolean optBoolean(int index, boolean defaultValue) {
- try {
- return this.getBoolean(index);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
- /**
- * Get the optional double value associated with an index. NaN is returned
- * if there is no value for the index, or if the value is not a number and
- * cannot be converted to a number.
- *
- * @param index
- * The index must be between 0 and length() - 1.
- * @return The value.
- */
- public double optDouble(int index) {
- return this.optDouble(index, Double.NaN);
- }
-
- /**
- * Get the optional double value associated with an index. The defaultValue
- * is returned if there is no value for the index, or if the value is not a
- * number and cannot be converted to a number.
- *
- * @param index
- * subscript
- * @param defaultValue
- * The default value.
- * @return The value.
- */
- public double optDouble(int index, double defaultValue) {
- try {
- return this.getDouble(index);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
- /**
- * Get the optional int value associated with an index. Zero is returned if
- * there is no value for the index, or if the value is not a number and
- * cannot be converted to a number.
- *
- * @param index
- * The index must be between 0 and length() - 1.
- * @return The value.
- */
- public int optInt(int index) {
- return this.optInt(index, 0);
- }
-
- /**
- * Get the optional int value associated with an index. The defaultValue is
- * returned if there is no value for the index, or if the value is not a
- * number and cannot be converted to a number.
- *
- * @param index
- * The index must be between 0 and length() - 1.
- * @param defaultValue
- * The default value.
- * @return The value.
- */
- public int optInt(int index, int defaultValue) {
- try {
- return this.getInt(index);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
- /**
- * Get the optional JSONArray associated with an index.
- *
- * @param index
- * subscript
- * @return A JSONArray value, or null if the index has no value, or if the
- * value is not a JSONArray.
- */
- public JSONArray optJSONArray(int index) {
- Object o = this.opt(index);
- return o instanceof JSONArray ? (JSONArray) o : null;
- }
-
- /**
- * Get the optional JSONObject associated with an index. Null is returned if
- * the key is not found, or null if the index has no value, or if the value
- * is not a JSONObject.
- *
- * @param index
- * The index must be between 0 and length() - 1.
- * @return A JSONObject value.
- */
- public JSONObject optJSONObject(int index) {
- Object o = this.opt(index);
- return o instanceof JSONObject ? (JSONObject) o : null;
- }
-
- /**
- * Get the optional long value associated with an index. Zero is returned if
- * there is no value for the index, or if the value is not a number and
- * cannot be converted to a number.
- *
- * @param index
- * The index must be between 0 and length() - 1.
- * @return The value.
- */
- public long optLong(int index) {
- return this.optLong(index, 0);
- }
-
- /**
- * Get the optional long value associated with an index. The defaultValue is
- * returned if there is no value for the index, or if the value is not a
- * number and cannot be converted to a number.
- *
- * @param index
- * The index must be between 0 and length() - 1.
- * @param defaultValue
- * The default value.
- * @return The value.
- */
- public long optLong(int index, long defaultValue) {
- try {
- return this.getLong(index);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
- /**
- * Get the optional string value associated with an index. It returns an
- * empty string if there is no value at that index. If the value is not a
- * string and is not null, then it is coverted to a string.
- *
- * @param index
- * The index must be between 0 and length() - 1.
- * @return A String value.
- */
- public String optString(int index) {
- return this.optString(index, "");
- }
-
- /**
- * Get the optional string associated with an index. The defaultValue is
- * returned if the key is not found.
- *
- * @param index
- * The index must be between 0 and length() - 1.
- * @param defaultValue
- * The default value.
- * @return A String value.
- */
- public String optString(int index, String defaultValue) {
- Object object = this.opt(index);
- return JSONObject.NULL.equals(object) ? defaultValue : object
- .toString();
- }
-
- /**
- * Append a boolean value. This increases the array's length by one.
- *
- * @param value
- * A boolean value.
- * @return this.
- */
- public JSONArray put(boolean value) {
- this.put(value ? Boolean.TRUE : Boolean.FALSE);
- return this;
- }
-
- /**
- * Put a value in the JSONArray, where the value will be a JSONArray which
- * is produced from a Collection.
- *
- * @param value
- * A Collection value.
- * @return this.
- */
- public JSONArray put(Collection value) {
- this.put(new JSONArray(value));
- return this;
- }
-
- /**
- * Append a double value. This increases the array's length by one.
- *
- * @param value
- * A double value.
- * @throws JSONException
- * if the value is not finite.
- * @return this.
- */
- public JSONArray put(double value) throws JSONException {
- Double d = new Double(value);
- JSONObject.testValidity(d);
- this.put(d);
- return this;
- }
-
- /**
- * Append an int value. This increases the array's length by one.
- *
- * @param value
- * An int value.
- * @return this.
- */
- public JSONArray put(int value) {
- this.put(new Integer(value));
- return this;
- }
-
- /**
- * Append an long value. This increases the array's length by one.
- *
- * @param value
- * A long value.
- * @return this.
- */
- public JSONArray put(long value) {
- this.put(new Long(value));
- return this;
- }
-
- /**
- * Put a value in the JSONArray, where the value will be a JSONObject which
- * is produced from a Map.
- *
- * @param value
- * A Map value.
- * @return this.
- */
- public JSONArray put(Map value) {
- this.put(new JSONObject(value));
- return this;
- }
-
- /**
- * Append an object value. This increases the array's length by one.
- *
- * @param value
- * An object value. The value should be a Boolean, Double,
- * Integer, JSONArray, JSONObject, Long, or String, or the
- * JSONObject.NULL object.
- * @return this.
- */
- public JSONArray put(Object value) {
- this.myArrayList.add(value);
- return this;
- }
-
- /**
- * Put or replace a boolean value in the JSONArray. If the index is greater
- * than the length of the JSONArray, then null elements will be added as
- * necessary to pad it out.
- *
- * @param index
- * The subscript.
- * @param value
- * A boolean value.
- * @return this.
- * @throws JSONException
- * If the index is negative.
- */
- public JSONArray put(int index, boolean value) throws JSONException {
- this.put(index, value ? Boolean.TRUE : Boolean.FALSE);
- return this;
- }
-
- /**
- * Put a value in the JSONArray, where the value will be a JSONArray which
- * is produced from a Collection.
- *
- * @param index
- * The subscript.
- * @param value
- * A Collection value.
- * @return this.
- * @throws JSONException
- * If the index is negative or if the value is not finite.
- */
- public JSONArray put(int index, Collection value) throws JSONException {
- this.put(index, new JSONArray(value));
- return this;
- }
-
- /**
- * Put or replace a double value. If the index is greater than the length of
- * the JSONArray, then null elements will be added as necessary to pad it
- * out.
- *
- * @param index
- * The subscript.
- * @param value
- * A double value.
- * @return this.
- * @throws JSONException
- * If the index is negative or if the value is not finite.
- */
- public JSONArray put(int index, double value) throws JSONException {
- this.put(index, new Double(value));
- return this;
- }
-
- /**
- * Put or replace an int value. If the index is greater than the length of
- * the JSONArray, then null elements will be added as necessary to pad it
- * out.
- *
- * @param index
- * The subscript.
- * @param value
- * An int value.
- * @return this.
- * @throws JSONException
- * If the index is negative.
- */
- public JSONArray put(int index, int value) throws JSONException {
- this.put(index, new Integer(value));
- return this;
- }
-
- /**
- * Put or replace a long value. If the index is greater than the length of
- * the JSONArray, then null elements will be added as necessary to pad it
- * out.
- *
- * @param index
- * The subscript.
- * @param value
- * A long value.
- * @return this.
- * @throws JSONException
- * If the index is negative.
- */
- public JSONArray put(int index, long value) throws JSONException {
- this.put(index, new Long(value));
- return this;
- }
-
- /**
- * Put a value in the JSONArray, where the value will be a JSONObject that
- * is produced from a Map.
- *
- * @param index
- * The subscript.
- * @param value
- * The Map value.
- * @return this.
- * @throws JSONException
- * If the index is negative or if the the value is an invalid
- * number.
- */
- public JSONArray put(int index, Map value) throws JSONException {
- this.put(index, new JSONObject(value));
- return this;
- }
-
- /**
- * Put or replace an object value in the JSONArray. If the index is greater
- * than the length of the JSONArray, then null elements will be added as
- * necessary to pad it out.
- *
- * @param index
- * The subscript.
- * @param value
- * The value to put into the array. The value should be a
- * Boolean, Double, Integer, JSONArray, JSONObject, Long, or
- * String, or the JSONObject.NULL object.
- * @return this.
- * @throws JSONException
- * If the index is negative or if the the value is an invalid
- * number.
- */
- public JSONArray put(int index, Object value) throws JSONException {
- JSONObject.testValidity(value);
- if (index < 0) {
- throw new JSONException("JSONArray[" + index + "] not found.");
- }
- if (index < this.length()) {
- this.myArrayList.set(index, value);
- } else {
- while (index != this.length()) {
- this.put(JSONObject.NULL);
- }
- this.put(value);
- }
- return this;
- }
-
- /**
- * Remove an index and close the hole.
- *
- * @param index
- * The index of the element to be removed.
- * @return The value that was associated with the index, or null if there
- * was no value.
- */
- public Object remove(int index) {
- Object o = this.opt(index);
- this.myArrayList.remove(index);
- return o;
- }
-
- /**
- * Produce a JSONObject by combining a JSONArray of names with the values of
- * this JSONArray.
- *
- * @param names
- * A JSONArray containing a list of key strings. These will be
- * paired with the values.
- * @return A JSONObject, or null if there are no names or if this JSONArray
- * has no values.
- * @throws JSONException
- * If any of the names are null.
- */
- public JSONObject toJSONObject(JSONArray names) throws JSONException {
- if (names == null || names.length() == 0 || this.length() == 0) {
- return null;
- }
- JSONObject jo = new JSONObject();
- for (int i = 0; i < names.length(); i += 1) {
- jo.put(names.getString(i), this.opt(i));
- }
- return jo;
- }
-
- /**
- * Make a JSON text of this JSONArray. For compactness, no unnecessary
- * whitespace is added. If it is not possible to produce a syntactically
- * correct JSON text then null will be returned instead. This could occur if
- * the array contains an invalid number.
- *
- * Warning: This method assumes that the data structure is acyclical.
- *
- * @return a printable, displayable, transmittable representation of the
- * array.
- */
- public String toString() {
- try {
- return this.toString(0);
- } catch (Exception e) {
- return null;
- }
- }
-
- /**
- * Make a prettyprinted JSON text of this JSONArray. Warning: This method
- * assumes that the data structure is acyclical.
- *
- * @param indentFactor
- * The number of spaces to add to each level of indentation.
- * @return a printable, displayable, transmittable representation of the
- * object, beginning with [
(left
- * bracket) and ending with ]
- * (right bracket).
- * @throws JSONException
- */
- public String toString(int indentFactor) throws JSONException {
- StringWriter sw = new StringWriter();
- synchronized (sw.getBuffer()) {
- return this.write(sw, indentFactor, 0).toString();
- }
- }
-
- /**
- * Write the contents of the JSONArray as JSON text to a writer. For
- * compactness, no whitespace is added.
- *
- * Warning: This method assumes that the data structure is acyclical.
- *
- * @return The writer.
- * @throws JSONException
- */
- public Writer write(Writer writer) throws JSONException {
- return this.write(writer, 0, 0);
- }
-
- /**
- * Write the contents of the JSONArray as JSON text to a writer. For
- * compactness, no whitespace is added.
- *
- * Warning: This method assumes that the data structure is acyclical.
- *
- * @param indentFactor
- * The number of spaces to add to each level of indentation.
- * @param indent
- * The indention of the top level.
- * @return The writer.
- * @throws JSONException
- */
- Writer write(Writer writer, int indentFactor, int indent)
- throws JSONException {
- try {
- boolean commanate = false;
- int length = this.length();
- writer.write('[');
-
- if (length == 1) {
- JSONObject.writeValue(writer, this.myArrayList.get(0),
- indentFactor, indent);
- } else if (length != 0) {
- final int newindent = indent + indentFactor;
-
- for (int i = 0; i < length; i += 1) {
- if (commanate) {
- writer.write(',');
- }
- if (indentFactor > 0) {
- writer.write('\n');
- }
- JSONObject.indent(writer, newindent);
- JSONObject.writeValue(writer, this.myArrayList.get(i),
- indentFactor, newindent);
- commanate = true;
- }
- if (indentFactor > 0) {
- writer.write('\n');
- }
- JSONObject.indent(writer, indent);
- }
- writer.write(']');
- return writer;
- } catch (IOException e) {
- throw new JSONException(e);
- }
- }
-}
diff --git a/restx-build/src/main/java/restx/build/org/json/JSONException.java b/restx-build/src/main/java/restx/build/org/json/JSONException.java
deleted file mode 100755
index 633ca7be1..000000000
--- a/restx-build/src/main/java/restx/build/org/json/JSONException.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package restx.build.org.json;
-
-/**
- * The JSONException is thrown by the JSON.org classes when things are amiss.
- *
- * @author JSON.org
- * @version 2013-02-10
- */
-public class JSONException extends RuntimeException {
- private static final long serialVersionUID = 0;
- private Throwable cause;
-
- /**
- * Constructs a JSONException with an explanatory message.
- *
- * @param message
- * Detail about the reason for the exception.
- */
- public JSONException(String message) {
- super(message);
- }
-
- /**
- * Constructs a new JSONException with the specified cause.
- */
- public JSONException(Throwable cause) {
- super(cause.getMessage());
- this.cause = cause;
- }
-
- /**
- * Returns the cause of this exception or null if the cause is nonexistent
- * or unknown.
- *
- * @return the cause of this exception or null if the cause is nonexistent
- * or unknown.
- */
- public Throwable getCause() {
- return this.cause;
- }
-}
diff --git a/restx-build/src/main/java/restx/build/org/json/JSONObject.java b/restx-build/src/main/java/restx/build/org/json/JSONObject.java
deleted file mode 100755
index 27b24f7fc..000000000
--- a/restx-build/src/main/java/restx/build/org/json/JSONObject.java
+++ /dev/null
@@ -1,1622 +0,0 @@
-package restx.build.org.json;
-
-/*
-Copyright (c) 2002 JSON.org
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-The Software shall be used for Good, not Evil.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-*/
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.*;
-
-/**
- * A JSONObject is an unordered collection of name/value pairs. Its external
- * form is a string wrapped in curly braces with colons between the names and
- * values, and commas between the values and names. The internal form is an
- * object having get
and opt
methods for accessing the
- * values by name, and put
methods for adding or replacing values
- * by name. The values can be any of these types: Boolean
,
- * JSONArray
, JSONObject
, Number
,
- * String
, or the JSONObject.NULL
object. A JSONObject
- * constructor can be used to convert an external form JSON text into an
- * internal form whose values can be retrieved with the get
and
- * opt
methods, or to convert values into a JSON text using the
- * put
and toString
methods. A get
method
- * returns a value if one can be found, and throws an exception if one cannot be
- * found. An opt
method returns a default value instead of throwing
- * an exception, and so is useful for obtaining optional values.
- *
- * The generic get()
and opt()
methods return an
- * object, which you can cast or query for type. There are also typed
- * get
and opt
methods that do type checking and type
- * coercion for you. The opt methods differ from the get methods in that they do
- * not throw. Instead, they return a specified value, such as null.
- *
- * The put
methods add or replace values in an object. For example,
- *
- *
- * myString = new JSONObject().put("JSON", "Hello, World!").toString();
- *
- *
- * produces the string {"JSON": "Hello, World"}
.
- *
- * The texts produced by the toString
methods strictly conform to
- * the JSON syntax rules. The constructors are more forgiving in the texts they
- * will accept:
- *
- * - An extra
,
(comma) may appear just
- * before the closing brace.
- * - Strings may be quoted with
'
(single
- * quote).
- * - Strings do not need to be quoted at all if they do not begin with a quote
- * or single quote, and if they do not contain leading or trailing spaces, and
- * if they do not contain any of these characters:
- *
{ } [ ] / \ : , = ; #
and if they do not look like numbers and
- * if they are not the reserved words true
, false
, or
- * null
.
- * - Keys can be followed by
=
or =>
as well as by
- * :
.
- * - Values can be followed by
;
(semicolon) as
- * well as by ,
(comma).
- *
- *
- * @author JSON.org
- * @version 2012-12-01
- */
-@SuppressWarnings("unchecked")
-public class JSONObject {
- /**
- * The maximum number of keys in the key pool.
- */
- private static final int keyPoolSize = 100;
-
- /**
- * Key pooling is like string interning, but without permanently tying up
- * memory. To help conserve memory, storage of duplicated key strings in
- * JSONObjects will be avoided by using a key pool to manage unique key
- * string objects. This is used by JSONObject.put(string, object).
- */
- private static HashMap keyPool = new HashMap(keyPoolSize);
-
- /**
- * JSONObject.NULL is equivalent to the value that JavaScript calls null,
- * whilst Java's null is equivalent to the value that JavaScript calls
- * undefined.
- */
- private static final class Null {
-
- /**
- * There is only intended to be a single instance of the NULL object,
- * so the clone method returns itself.
- * @return NULL.
- */
- protected final Object clone() {
- return this;
- }
-
- /**
- * A Null object is equal to the null value and to itself.
- * @param object An object to test for nullness.
- * @return true if the object parameter is the JSONObject.NULL object
- * or null.
- */
- public boolean equals(Object object) {
- return object == null || object == this;
- }
-
- /**
- * Get the "null" string value.
- * @return The string "null".
- */
- public String toString() {
- return "null";
- }
- }
-
-
- /**
- * The map where the JSONObject's properties are kept.
- */
- private final Map map;
-
-
- /**
- * It is sometimes more convenient and less ambiguous to have a
- * NULL
object than to use Java's null
value.
- * JSONObject.NULL.equals(null)
returns true
.
- * JSONObject.NULL.toString()
returns "null"
.
- */
- public static final Object NULL = new Null();
-
-
- /**
- * Construct an empty JSONObject.
- */
- public JSONObject() {
- this.map = new LinkedHashMap();
- }
-
-
- /**
- * Construct a JSONObject from a subset of another JSONObject.
- * An array of strings is used to identify the keys that should be copied.
- * Missing keys are ignored.
- * @param jo A JSONObject.
- * @param names An array of strings.
- * @throws JSONException
- * @exception JSONException If a value is a non-finite number or if a name is duplicated.
- */
- public JSONObject(JSONObject jo, String[] names) {
- this();
- for (int i = 0; i < names.length; i += 1) {
- try {
- this.putOnce(names[i], jo.opt(names[i]));
- } catch (Exception ignore) {
- }
- }
- }
-
-
- /**
- * Construct a JSONObject from a JSONTokener.
- * @param x A JSONTokener object containing the source string.
- * @throws JSONException If there is a syntax error in the source string
- * or a duplicated key.
- */
- public JSONObject(JSONTokener x) throws JSONException {
- this();
- char c;
- String key;
-
- if (x.nextClean() != '{') {
- throw x.syntaxError("A JSONObject text must begin with '{'");
- }
- for (;;) {
- c = x.nextClean();
- switch (c) {
- case 0:
- throw x.syntaxError("A JSONObject text must end with '}'");
- case '}':
- return;
- default:
- x.back();
- key = x.nextValue().toString();
- }
-
-// The key is followed by ':'. We will also tolerate '=' or '=>'.
-
- c = x.nextClean();
- if (c == '=') {
- if (x.next() != '>') {
- x.back();
- }
- } else if (c != ':') {
- throw x.syntaxError("Expected a ':' after a key");
- }
- this.putOnce(key, x.nextValue());
-
-// Pairs are separated by ','. We will also tolerate ';'.
-
- switch (x.nextClean()) {
- case ';':
- case ',':
- if (x.nextClean() == '}') {
- return;
- }
- x.back();
- break;
- case '}':
- return;
- default:
- throw x.syntaxError("Expected a ',' or '}'");
- }
- }
- }
-
-
- /**
- * Construct a JSONObject from a Map.
- *
- * @param map A map object that can be used to initialize the contents of
- * the JSONObject.
- * @throws JSONException
- */
- public JSONObject(Map map) {
- this.map = new HashMap();
- if (map != null) {
- Iterator i = map.entrySet().iterator();
- while (i.hasNext()) {
- Map.Entry e = (Map.Entry)i.next();
- Object value = e.getValue();
- if (value != null) {
- this.map.put(e.getKey(), wrap(value));
- }
- }
- }
- }
-
-
- /**
- * Construct a JSONObject from an Object using bean getters.
- * It reflects on all of the public methods of the object.
- * For each of the methods with no parameters and a name starting
- * with "get"
or "is"
followed by an uppercase letter,
- * the method is invoked, and a key and the value returned from the getter method
- * are put into the new JSONObject.
- *
- * The key is formed by removing the "get"
or "is"
prefix.
- * If the second remaining character is not upper case, then the first
- * character is converted to lower case.
- *
- * For example, if an object has a method named "getName"
, and
- * if the result of calling object.getName()
is "Larry Fine"
,
- * then the JSONObject will contain "name": "Larry Fine"
.
- *
- * @param bean An object that has getter methods that should be used
- * to make a JSONObject.
- */
- public JSONObject(Object bean) {
- this();
- this.populateMap(bean);
- }
-
-
- /**
- * Construct a JSONObject from an Object, using reflection to find the
- * public members. The resulting JSONObject's keys will be the strings
- * from the names array, and the values will be the field values associated
- * with those keys in the object. If a key is not found or not visible,
- * then it will not be copied into the new JSONObject.
- * @param object An object that has fields that should be used to make a
- * JSONObject.
- * @param names An array of strings, the names of the fields to be obtained
- * from the object.
- */
- public JSONObject(Object object, String names[]) {
- this();
- Class c = object.getClass();
- for (int i = 0; i < names.length; i += 1) {
- String name = names[i];
- try {
- this.putOpt(name, c.getField(name).get(object));
- } catch (Exception ignore) {
- }
- }
- }
-
-
- /**
- * Construct a JSONObject from a source JSON text string.
- * This is the most commonly used JSONObject constructor.
- * @param source A string beginning
- * with {
(left brace) and ending
- * with }
(right brace).
- * @exception JSONException If there is a syntax error in the source
- * string or a duplicated key.
- */
- public JSONObject(String source) throws JSONException {
- this(new JSONTokener(source));
- }
-
-
- /**
- * Construct a JSONObject from a ResourceBundle.
- * @param baseName The ResourceBundle base name.
- * @param locale The Locale to load the ResourceBundle for.
- * @throws JSONException If any JSONExceptions are detected.
- */
- public JSONObject(String baseName, Locale locale) throws JSONException {
- this();
- ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale,
- Thread.currentThread().getContextClassLoader());
-
-// Iterate through the keys in the bundle.
-
- Enumeration keys = bundle.getKeys();
- while (keys.hasMoreElements()) {
- Object key = keys.nextElement();
- if (key instanceof String) {
-
-// Go through the path, ensuring that there is a nested JSONObject for each
-// segment except the last. Add the value using the last segment's name into
-// the deepest nested JSONObject.
-
- String[] path = ((String)key).split("\\.");
- int last = path.length - 1;
- JSONObject target = this;
- for (int i = 0; i < last; i += 1) {
- String segment = path[i];
- JSONObject nextTarget = target.optJSONObject(segment);
- if (nextTarget == null) {
- nextTarget = new JSONObject();
- target.put(segment, nextTarget);
- }
- target = nextTarget;
- }
- target.put(path[last], bundle.getString((String)key));
- }
- }
- }
-
-
- /**
- * Accumulate values under a key. It is similar to the put method except
- * that if there is already an object stored under the key then a
- * JSONArray is stored under the key to hold all of the accumulated values.
- * If there is already a JSONArray, then the new value is appended to it.
- * In contrast, the put method replaces the previous value.
- *
- * If only one value is accumulated that is not a JSONArray, then the
- * result will be the same as using put. But if multiple values are
- * accumulated, then the result will be like append.
- * @param key A key string.
- * @param value An object to be accumulated under the key.
- * @return this.
- * @throws JSONException If the value is an invalid number
- * or if the key is null.
- */
- public JSONObject accumulate(
- String key,
- Object value
- ) throws JSONException {
- testValidity(value);
- Object object = this.opt(key);
- if (object == null) {
- this.put(key, value instanceof JSONArray
- ? new JSONArray().put(value)
- : value);
- } else if (object instanceof JSONArray) {
- ((JSONArray)object).put(value);
- } else {
- this.put(key, new JSONArray().put(object).put(value));
- }
- return this;
- }
-
-
- /**
- * Append values to the array under a key. If the key does not exist in the
- * JSONObject, then the key is put in the JSONObject with its value being a
- * JSONArray containing the value parameter. If the key was already
- * associated with a JSONArray, then the value parameter is appended to it.
- * @param key A key string.
- * @param value An object to be accumulated under the key.
- * @return this.
- * @throws JSONException If the key is null or if the current value
- * associated with the key is not a JSONArray.
- */
- public JSONObject append(String key, Object value) throws JSONException {
- testValidity(value);
- Object object = this.opt(key);
- if (object == null) {
- this.put(key, new JSONArray().put(value));
- } else if (object instanceof JSONArray) {
- this.put(key, ((JSONArray)object).put(value));
- } else {
- throw new JSONException("JSONObject[" + key +
- "] is not a JSONArray.");
- }
- return this;
- }
-
-
- /**
- * Produce a string from a double. The string "null" will be returned if
- * the number is not finite.
- * @param d A double.
- * @return A String.
- */
- public static String doubleToString(double d) {
- if (Double.isInfinite(d) || Double.isNaN(d)) {
- return "null";
- }
-
-// Shave off trailing zeros and decimal point, if possible.
-
- String string = Double.toString(d);
- if (string.indexOf('.') > 0 && string.indexOf('e') < 0 &&
- string.indexOf('E') < 0) {
- while (string.endsWith("0")) {
- string = string.substring(0, string.length() - 1);
- }
- if (string.endsWith(".")) {
- string = string.substring(0, string.length() - 1);
- }
- }
- return string;
- }
-
-
- /**
- * Get the value object associated with a key.
- *
- * @param key A key string.
- * @return The object associated with the key.
- * @throws JSONException if the key is not found.
- */
- public Object get(String key) throws JSONException {
- if (key == null) {
- throw new JSONException("Null key.");
- }
- Object object = this.opt(key);
- if (object == null) {
- throw new JSONException("JSONObject[" + quote(key) +
- "] not found.");
- }
- return object;
- }
-
-
- /**
- * Get the boolean value associated with a key.
- *
- * @param key A key string.
- * @return The truth.
- * @throws JSONException
- * if the value is not a Boolean or the String "true" or "false".
- */
- public boolean getBoolean(String key) throws JSONException {
- Object object = this.get(key);
- if (object.equals(Boolean.FALSE) ||
- (object instanceof String &&
- ((String)object).equalsIgnoreCase("false"))) {
- return false;
- } else if (object.equals(Boolean.TRUE) ||
- (object instanceof String &&
- ((String)object).equalsIgnoreCase("true"))) {
- return true;
- }
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not a Boolean.");
- }
-
-
- /**
- * Get the double value associated with a key.
- * @param key A key string.
- * @return The numeric value.
- * @throws JSONException if the key is not found or
- * if the value is not a Number object and cannot be converted to a number.
- */
- public double getDouble(String key) throws JSONException {
- Object object = this.get(key);
- try {
- return object instanceof Number
- ? ((Number)object).doubleValue()
- : Double.parseDouble((String)object);
- } catch (Exception e) {
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not a number.");
- }
- }
-
-
- /**
- * Get the int value associated with a key.
- *
- * @param key A key string.
- * @return The integer value.
- * @throws JSONException if the key is not found or if the value cannot
- * be converted to an integer.
- */
- public int getInt(String key) throws JSONException {
- Object object = this.get(key);
- try {
- return object instanceof Number
- ? ((Number)object).intValue()
- : Integer.parseInt((String)object);
- } catch (Exception e) {
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not an int.");
- }
- }
-
-
- /**
- * Get the JSONArray value associated with a key.
- *
- * @param key A key string.
- * @return A JSONArray which is the value.
- * @throws JSONException if the key is not found or
- * if the value is not a JSONArray.
- */
- public JSONArray getJSONArray(String key) throws JSONException {
- Object object = this.get(key);
- if (object instanceof JSONArray) {
- return (JSONArray)object;
- }
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not a JSONArray.");
- }
-
-
- /**
- * Get the JSONObject value associated with a key.
- *
- * @param key A key string.
- * @return A JSONObject which is the value.
- * @throws JSONException if the key is not found or
- * if the value is not a JSONObject.
- */
- public JSONObject getJSONObject(String key) throws JSONException {
- Object object = this.get(key);
- if (object instanceof JSONObject) {
- return (JSONObject)object;
- }
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not a JSONObject.");
- }
-
-
- /**
- * Get the long value associated with a key.
- *
- * @param key A key string.
- * @return The long value.
- * @throws JSONException if the key is not found or if the value cannot
- * be converted to a long.
- */
- public long getLong(String key) throws JSONException {
- Object object = this.get(key);
- try {
- return object instanceof Number
- ? ((Number)object).longValue()
- : Long.parseLong((String)object);
- } catch (Exception e) {
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not a long.");
- }
- }
-
-
- /**
- * Get an array of field names from a JSONObject.
- *
- * @return An array of field names, or null if there are no names.
- */
- public static String[] getNames(JSONObject jo) {
- int length = jo.length();
- if (length == 0) {
- return null;
- }
- Iterator iterator = jo.keys();
- String[] names = new String[length];
- int i = 0;
- while (iterator.hasNext()) {
- names[i] = (String)iterator.next();
- i += 1;
- }
- return names;
- }
-
-
- /**
- * Get an array of field names from an Object.
- *
- * @return An array of field names, or null if there are no names.
- */
- public static String[] getNames(Object object) {
- if (object == null) {
- return null;
- }
- Class klass = object.getClass();
- Field[] fields = klass.getFields();
- int length = fields.length;
- if (length == 0) {
- return null;
- }
- String[] names = new String[length];
- for (int i = 0; i < length; i += 1) {
- names[i] = fields[i].getName();
- }
- return names;
- }
-
-
- /**
- * Get the string associated with a key.
- *
- * @param key A key string.
- * @return A string which is the value.
- * @throws JSONException if there is no string value for the key.
- */
- public String getString(String key) throws JSONException {
- Object object = this.get(key);
- if (object instanceof String) {
- return (String)object;
- }
- throw new JSONException("JSONObject[" + quote(key) +
- "] not a string.");
- }
-
-
- /**
- * Determine if the JSONObject contains a specific key.
- * @param key A key string.
- * @return true if the key exists in the JSONObject.
- */
- public boolean has(String key) {
- return this.map.containsKey(key);
- }
-
-
- /**
- * Increment a property of a JSONObject. If there is no such property,
- * create one with a value of 1. If there is such a property, and if
- * it is an Integer, Long, Double, or Float, then add one to it.
- * @param key A key string.
- * @return this.
- * @throws JSONException If there is already a property with this name
- * that is not an Integer, Long, Double, or Float.
- */
- public JSONObject increment(String key) throws JSONException {
- Object value = this.opt(key);
- if (value == null) {
- this.put(key, 1);
- } else if (value instanceof Integer) {
- this.put(key, ((Integer)value).intValue() + 1);
- } else if (value instanceof Long) {
- this.put(key, ((Long)value).longValue() + 1);
- } else if (value instanceof Double) {
- this.put(key, ((Double)value).doubleValue() + 1);
- } else if (value instanceof Float) {
- this.put(key, ((Float)value).floatValue() + 1);
- } else {
- throw new JSONException("Unable to increment [" + quote(key) + "].");
- }
- return this;
- }
-
-
- /**
- * Determine if the value associated with the key is null or if there is
- * no value.
- * @param key A key string.
- * @return true if there is no value associated with the key or if
- * the value is the JSONObject.NULL object.
- */
- public boolean isNull(String key) {
- return JSONObject.NULL.equals(this.opt(key));
- }
-
-
- /**
- * Get an enumeration of the keys of the JSONObject.
- *
- * @return An iterator of the keys.
- */
- public Iterator keys() {
- return this.keySet().iterator();
- }
-
-
- /**
- * Get a set of keys of the JSONObject.
- *
- * @return A keySet.
- */
- public Set keySet() {
- return this.map.keySet();
- }
-
-
- /**
- * Get the number of keys stored in the JSONObject.
- *
- * @return The number of keys in the JSONObject.
- */
- public int length() {
- return this.map.size();
- }
-
-
- /**
- * Produce a JSONArray containing the names of the elements of this
- * JSONObject.
- * @return A JSONArray containing the key strings, or null if the JSONObject
- * is empty.
- */
- public JSONArray names() {
- JSONArray ja = new JSONArray();
- Iterator keys = this.keys();
- while (keys.hasNext()) {
- ja.put(keys.next());
- }
- return ja.length() == 0 ? null : ja;
- }
-
- /**
- * Produce a string from a Number.
- * @param number A Number
- * @return A String.
- * @throws JSONException If n is a non-finite number.
- */
- public static String numberToString(Number number)
- throws JSONException {
- if (number == null) {
- throw new JSONException("Null pointer");
- }
- testValidity(number);
-
-// Shave off trailing zeros and decimal point, if possible.
-
- String string = number.toString();
- if (string.indexOf('.') > 0 && string.indexOf('e') < 0 &&
- string.indexOf('E') < 0) {
- while (string.endsWith("0")) {
- string = string.substring(0, string.length() - 1);
- }
- if (string.endsWith(".")) {
- string = string.substring(0, string.length() - 1);
- }
- }
- return string;
- }
-
-
- /**
- * Get an optional value associated with a key.
- * @param key A key string.
- * @return An object which is the value, or null if there is no value.
- */
- public Object opt(String key) {
- return key == null ? null : this.map.get(key);
- }
-
-
- /**
- * Get an optional boolean associated with a key.
- * It returns false if there is no such key, or if the value is not
- * Boolean.TRUE or the String "true".
- *
- * @param key A key string.
- * @return The truth.
- */
- public boolean optBoolean(String key) {
- return this.optBoolean(key, false);
- }
-
-
- /**
- * Get an optional boolean associated with a key.
- * It returns the defaultValue if there is no such key, or if it is not
- * a Boolean or the String "true" or "false" (case insensitive).
- *
- * @param key A key string.
- * @param defaultValue The default.
- * @return The truth.
- */
- public boolean optBoolean(String key, boolean defaultValue) {
- try {
- return this.getBoolean(key);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
-
- /**
- * Get an optional double associated with a key,
- * or NaN if there is no such key or if its value is not a number.
- * If the value is a string, an attempt will be made to evaluate it as
- * a number.
- *
- * @param key A string which is the key.
- * @return An object which is the value.
- */
- public double optDouble(String key) {
- return this.optDouble(key, Double.NaN);
- }
-
-
- /**
- * Get an optional double associated with a key, or the
- * defaultValue if there is no such key or if its value is not a number.
- * If the value is a string, an attempt will be made to evaluate it as
- * a number.
- *
- * @param key A key string.
- * @param defaultValue The default.
- * @return An object which is the value.
- */
- public double optDouble(String key, double defaultValue) {
- try {
- return this.getDouble(key);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
-
- /**
- * Get an optional int value associated with a key,
- * or zero if there is no such key or if the value is not a number.
- * If the value is a string, an attempt will be made to evaluate it as
- * a number.
- *
- * @param key A key string.
- * @return An object which is the value.
- */
- public int optInt(String key) {
- return this.optInt(key, 0);
- }
-
-
- /**
- * Get an optional int value associated with a key,
- * or the default if there is no such key or if the value is not a number.
- * If the value is a string, an attempt will be made to evaluate it as
- * a number.
- *
- * @param key A key string.
- * @param defaultValue The default.
- * @return An object which is the value.
- */
- public int optInt(String key, int defaultValue) {
- try {
- return this.getInt(key);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
-
- /**
- * Get an optional JSONArray associated with a key.
- * It returns null if there is no such key, or if its value is not a
- * JSONArray.
- *
- * @param key A key string.
- * @return A JSONArray which is the value.
- */
- public JSONArray optJSONArray(String key) {
- Object o = this.opt(key);
- return o instanceof JSONArray ? (JSONArray)o : null;
- }
-
-
- /**
- * Get an optional JSONObject associated with a key.
- * It returns null if there is no such key, or if its value is not a
- * JSONObject.
- *
- * @param key A key string.
- * @return A JSONObject which is the value.
- */
- public JSONObject optJSONObject(String key) {
- Object object = this.opt(key);
- return object instanceof JSONObject ? (JSONObject)object : null;
- }
-
-
- /**
- * Get an optional long value associated with a key,
- * or zero if there is no such key or if the value is not a number.
- * If the value is a string, an attempt will be made to evaluate it as
- * a number.
- *
- * @param key A key string.
- * @return An object which is the value.
- */
- public long optLong(String key) {
- return this.optLong(key, 0);
- }
-
-
- /**
- * Get an optional long value associated with a key,
- * or the default if there is no such key or if the value is not a number.
- * If the value is a string, an attempt will be made to evaluate it as
- * a number.
- *
- * @param key A key string.
- * @param defaultValue The default.
- * @return An object which is the value.
- */
- public long optLong(String key, long defaultValue) {
- try {
- return this.getLong(key);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
-
- /**
- * Get an optional string associated with a key.
- * It returns an empty string if there is no such key. If the value is not
- * a string and is not null, then it is converted to a string.
- *
- * @param key A key string.
- * @return A string which is the value.
- */
- public String optString(String key) {
- return this.optString(key, "");
- }
-
-
- /**
- * Get an optional string associated with a key.
- * It returns the defaultValue if there is no such key.
- *
- * @param key A key string.
- * @param defaultValue The default.
- * @return A string which is the value.
- */
- public String optString(String key, String defaultValue) {
- Object object = this.opt(key);
- return NULL.equals(object) ? defaultValue : object.toString();
- }
-
-
- private void populateMap(Object bean) {
- Class klass = bean.getClass();
-
-// If klass is a System class then set includeSuperClass to false.
-
- boolean includeSuperClass = klass.getClassLoader() != null;
-
- Method[] methods = includeSuperClass
- ? klass.getMethods()
- : klass.getDeclaredMethods();
- for (int i = 0; i < methods.length; i += 1) {
- try {
- Method method = methods[i];
- if (Modifier.isPublic(method.getModifiers())) {
- String name = method.getName();
- String key = "";
- if (name.startsWith("get")) {
- if ("getClass".equals(name) ||
- "getDeclaringClass".equals(name)) {
- key = "";
- } else {
- key = name.substring(3);
- }
- } else if (name.startsWith("is")) {
- key = name.substring(2);
- }
- if (key.length() > 0 &&
- Character.isUpperCase(key.charAt(0)) &&
- method.getParameterTypes().length == 0) {
- if (key.length() == 1) {
- key = key.toLowerCase();
- } else if (!Character.isUpperCase(key.charAt(1))) {
- key = key.substring(0, 1).toLowerCase() +
- key.substring(1);
- }
-
- Object result = method.invoke(bean, (Object[])null);
- if (result != null) {
- this.map.put(key, wrap(result));
- }
- }
- }
- } catch (Exception ignore) {
- }
- }
- }
-
-
- /**
- * Put a key/boolean pair in the JSONObject.
- *
- * @param key A key string.
- * @param value A boolean which is the value.
- * @return this.
- * @throws JSONException If the key is null.
- */
- public JSONObject put(String key, boolean value) throws JSONException {
- this.put(key, value ? Boolean.TRUE : Boolean.FALSE);
- return this;
- }
-
-
- /**
- * Put a key/value pair in the JSONObject, where the value will be a
- * JSONArray which is produced from a Collection.
- * @param key A key string.
- * @param value A Collection value.
- * @return this.
- * @throws JSONException
- */
- public JSONObject put(String key, Collection value) throws JSONException {
- this.put(key, new JSONArray(value));
- return this;
- }
-
-
- /**
- * Put a key/double pair in the JSONObject.
- *
- * @param key A key string.
- * @param value A double which is the value.
- * @return this.
- * @throws JSONException If the key is null or if the number is invalid.
- */
- public JSONObject put(String key, double value) throws JSONException {
- this.put(key, new Double(value));
- return this;
- }
-
-
- /**
- * Put a key/int pair in the JSONObject.
- *
- * @param key A key string.
- * @param value An int which is the value.
- * @return this.
- * @throws JSONException If the key is null.
- */
- public JSONObject put(String key, int value) throws JSONException {
- this.put(key, new Integer(value));
- return this;
- }
-
-
- /**
- * Put a key/long pair in the JSONObject.
- *
- * @param key A key string.
- * @param value A long which is the value.
- * @return this.
- * @throws JSONException If the key is null.
- */
- public JSONObject put(String key, long value) throws JSONException {
- this.put(key, new Long(value));
- return this;
- }
-
-
- /**
- * Put a key/value pair in the JSONObject, where the value will be a
- * JSONObject which is produced from a Map.
- * @param key A key string.
- * @param value A Map value.
- * @return this.
- * @throws JSONException
- */
- public JSONObject put(String key, Map value) throws JSONException {
- this.put(key, new JSONObject(value));
- return this;
- }
-
-
- /**
- * Put a key/value pair in the JSONObject. If the value is null,
- * then the key will be removed from the JSONObject if it is present.
- * @param key A key string.
- * @param value An object which is the value. It should be of one of these
- * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, String,
- * or the JSONObject.NULL object.
- * @return this.
- * @throws JSONException If the value is non-finite number
- * or if the key is null.
- */
- public JSONObject put(String key, Object value) throws JSONException {
- String pooled;
- if (key == null) {
- throw new JSONException("Null key.");
- }
- if (value != null) {
- testValidity(value);
- pooled = (String)keyPool.get(key);
- if (pooled == null) {
- if (keyPool.size() >= keyPoolSize) {
- keyPool = new HashMap(keyPoolSize);
- }
- keyPool.put(key, key);
- } else {
- key = pooled;
- }
- this.map.put(key, value);
- } else {
- this.remove(key);
- }
- return this;
- }
-
-
- /**
- * Put a key/value pair in the JSONObject, but only if the key and the
- * value are both non-null, and only if there is not already a member
- * with that name.
- * @param key
- * @param value
- * @return his.
- * @throws JSONException if the key is a duplicate
- */
- public JSONObject putOnce(String key, Object value) throws JSONException {
- if (key != null && value != null) {
- if (this.opt(key) != null) {
- throw new JSONException("Duplicate key \"" + key + "\"");
- }
- this.put(key, value);
- }
- return this;
- }
-
-
- /**
- * Put a key/value pair in the JSONObject, but only if the
- * key and the value are both non-null.
- * @param key A key string.
- * @param value An object which is the value. It should be of one of these
- * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, String,
- * or the JSONObject.NULL object.
- * @return this.
- * @throws JSONException If the value is a non-finite number.
- */
- public JSONObject putOpt(String key, Object value) throws JSONException {
- if (key != null && value != null) {
- this.put(key, value);
- }
- return this;
- }
-
-
- /**
- * Produce a string in double quotes with backslash sequences in all the
- * right places. A backslash will be inserted within </, producing <\/,
- * allowing JSON text to be delivered in HTML. In JSON text, a string
- * cannot contain a control character or an unescaped quote or backslash.
- * @param string A String
- * @return A String correctly formatted for insertion in a JSON text.
- */
- public static String quote(String string) {
- StringWriter sw = new StringWriter();
- synchronized (sw.getBuffer()) {
- try {
- return quote(string, sw).toString();
- } catch (IOException ignored) {
- // will never happen - we are writing to a string writer
- return "";
- }
- }
- }
-
- public static Writer quote(String string, Writer w) throws IOException {
- if (string == null || string.length() == 0) {
- w.write("\"\"");
- return w;
- }
-
- char b;
- char c = 0;
- String hhhh;
- int i;
- int len = string.length();
-
- w.write('"');
- for (i = 0; i < len; i += 1) {
- b = c;
- c = string.charAt(i);
- switch (c) {
- case '\\':
- case '"':
- w.write('\\');
- w.write(c);
- break;
- case '/':
- if (b == '<') {
- w.write('\\');
- }
- w.write(c);
- break;
- case '\b':
- w.write("\\b");
- break;
- case '\t':
- w.write("\\t");
- break;
- case '\n':
- w.write("\\n");
- break;
- case '\f':
- w.write("\\f");
- break;
- case '\r':
- w.write("\\r");
- break;
- default:
- if (c < ' ' || (c >= '\u0080' && c < '\u00a0')
- || (c >= '\u2000' && c < '\u2100')) {
- w.write("\\u");
- hhhh = Integer.toHexString(c);
- w.write("0000", 0, 4 - hhhh.length());
- w.write(hhhh);
- } else {
- w.write(c);
- }
- }
- }
- w.write('"');
- return w;
- }
-
- /**
- * Remove a name and its value, if present.
- * @param key The name to be removed.
- * @return The value that was associated with the name,
- * or null if there was no value.
- */
- public Object remove(String key) {
- return this.map.remove(key);
- }
-
- /**
- * Try to convert a string into a number, boolean, or null. If the string
- * can't be converted, return the string.
- * @param string A String.
- * @return A simple JSON value.
- */
- public static Object stringToValue(String string) {
- Double d;
- if (string.equals("")) {
- return string;
- }
- if (string.equalsIgnoreCase("true")) {
- return Boolean.TRUE;
- }
- if (string.equalsIgnoreCase("false")) {
- return Boolean.FALSE;
- }
- if (string.equalsIgnoreCase("null")) {
- return JSONObject.NULL;
- }
-
- /*
- * If it might be a number, try converting it.
- * If a number cannot be produced, then the value will just
- * be a string. Note that the plus and implied string
- * conventions are non-standard. A JSON parser may accept
- * non-JSON forms as long as it accepts all correct JSON forms.
- */
-
- char b = string.charAt(0);
- if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') {
- try {
- if (string.indexOf('.') > -1 ||
- string.indexOf('e') > -1 || string.indexOf('E') > -1) {
- d = Double.valueOf(string);
- if (!d.isInfinite() && !d.isNaN()) {
- return d;
- }
- } else {
- Long myLong = new Long(string);
- if (myLong.longValue() == myLong.intValue()) {
- return new Integer(myLong.intValue());
- } else {
- return myLong;
- }
- }
- } catch (Exception ignore) {
- }
- }
- return string;
- }
-
-
- /**
- * Throw an exception if the object is a NaN or infinite number.
- * @param o The object to test.
- * @throws JSONException If o is a non-finite number.
- */
- public static void testValidity(Object o) throws JSONException {
- if (o != null) {
- if (o instanceof Double) {
- if (((Double)o).isInfinite() || ((Double)o).isNaN()) {
- throw new JSONException(
- "JSON does not allow non-finite numbers.");
- }
- } else if (o instanceof Float) {
- if (((Float)o).isInfinite() || ((Float)o).isNaN()) {
- throw new JSONException(
- "JSON does not allow non-finite numbers.");
- }
- }
- }
- }
-
-
- /**
- * Produce a JSONArray containing the values of the members of this
- * JSONObject.
- * @param names A JSONArray containing a list of key strings. This
- * determines the sequence of the values in the result.
- * @return A JSONArray of values.
- * @throws JSONException If any of the values are non-finite numbers.
- */
- public JSONArray toJSONArray(JSONArray names) throws JSONException {
- if (names == null || names.length() == 0) {
- return null;
- }
- JSONArray ja = new JSONArray();
- for (int i = 0; i < names.length(); i += 1) {
- ja.put(this.opt(names.getString(i)));
- }
- return ja;
- }
-
- /**
- * Make a JSON text of this JSONObject. For compactness, no whitespace
- * is added. If this would not result in a syntactically correct JSON text,
- * then null will be returned instead.
- *
- * Warning: This method assumes that the data structure is acyclical.
- *
- * @return a printable, displayable, portable, transmittable
- * representation of the object, beginning
- * with {
(left brace) and ending
- * with }
(right brace).
- */
- public String toString() {
- try {
- return this.toString(0);
- } catch (Exception e) {
- return null;
- }
- }
-
-
- /**
- * Make a prettyprinted JSON text of this JSONObject.
- *
- * Warning: This method assumes that the data structure is acyclical.
- * @param indentFactor The number of spaces to add to each level of
- * indentation.
- * @return a printable, displayable, portable, transmittable
- * representation of the object, beginning
- * with {
(left brace) and ending
- * with }
(right brace).
- * @throws JSONException If the object contains an invalid number.
- */
- public String toString(int indentFactor) throws JSONException {
- StringWriter w = new StringWriter();
- synchronized (w.getBuffer()) {
- return this.write(w, indentFactor, 0).toString();
- }
- }
-
- /**
- * Make a JSON text of an Object value. If the object has an
- * value.toJSONString() method, then that method will be used to produce
- * the JSON text. The method is required to produce a strictly
- * conforming text. If the object does not contain a toJSONString
- * method (which is the most common case), then a text will be
- * produced by other means. If the value is an array or Collection,
- * then a JSONArray will be made from it and its toJSONString method
- * will be called. If the value is a MAP, then a JSONObject will be made
- * from it and its toJSONString method will be called. Otherwise, the
- * value's toString method will be called, and the result will be quoted.
- *
- *
- * Warning: This method assumes that the data structure is acyclical.
- * @param value The value to be serialized.
- * @return a printable, displayable, transmittable
- * representation of the object, beginning
- * with {
(left brace) and ending
- * with }
(right brace).
- * @throws JSONException If the value is or contains an invalid number.
- */
- public static String valueToString(Object value) throws JSONException {
- if (value == null || value.equals(null)) {
- return "null";
- }
- if (value instanceof JSONString) {
- Object object;
- try {
- object = ((JSONString)value).toJSONString();
- } catch (Exception e) {
- throw new JSONException(e);
- }
- if (object instanceof String) {
- return (String)object;
- }
- throw new JSONException("Bad value from toJSONString: " + object);
- }
- if (value instanceof Number) {
- return numberToString((Number) value);
- }
- if (value instanceof Boolean || value instanceof JSONObject ||
- value instanceof JSONArray) {
- return value.toString();
- }
- if (value instanceof Map) {
- return new JSONObject((Map)value).toString();
- }
- if (value instanceof Collection) {
- return new JSONArray((Collection)value).toString();
- }
- if (value.getClass().isArray()) {
- return new JSONArray(value).toString();
- }
- return quote(value.toString());
- }
-
- /**
- * Wrap an object, if necessary. If the object is null, return the NULL
- * object. If it is an array or collection, wrap it in a JSONArray. If
- * it is a map, wrap it in a JSONObject. If it is a standard property
- * (Double, String, et al) then it is already wrapped. Otherwise, if it
- * comes from one of the java packages, turn it into a string. And if
- * it doesn't, try to wrap it in a JSONObject. If the wrapping fails,
- * then null is returned.
- *
- * @param object The object to wrap
- * @return The wrapped value
- */
- public static Object wrap(Object object) {
- try {
- if (object == null) {
- return NULL;
- }
- if (object instanceof JSONObject || object instanceof JSONArray ||
- NULL.equals(object) || object instanceof JSONString ||
- object instanceof Byte || object instanceof Character ||
- object instanceof Short || object instanceof Integer ||
- object instanceof Long || object instanceof Boolean ||
- object instanceof Float || object instanceof Double ||
- object instanceof String) {
- return object;
- }
-
- if (object instanceof Collection) {
- return new JSONArray((Collection)object);
- }
- if (object.getClass().isArray()) {
- return new JSONArray(object);
- }
- if (object instanceof Map) {
- return new JSONObject((Map)object);
- }
- Package objectPackage = object.getClass().getPackage();
- String objectPackageName = objectPackage != null
- ? objectPackage.getName()
- : "";
- if (
- objectPackageName.startsWith("java.") ||
- objectPackageName.startsWith("javax.") ||
- object.getClass().getClassLoader() == null
- ) {
- return object.toString();
- }
- return new JSONObject(object);
- } catch(Exception exception) {
- return null;
- }
- }
-
-
- /**
- * Write the contents of the JSONObject as JSON text to a writer.
- * For compactness, no whitespace is added.
- *
- * Warning: This method assumes that the data structure is acyclical.
- *
- * @return The writer.
- * @throws JSONException
- */
- public Writer write(Writer writer) throws JSONException {
- return this.write(writer, 0, 0);
- }
-
-
- static final Writer writeValue(Writer writer, Object value,
- int indentFactor, int indent) throws JSONException, IOException {
- if (value == null || value.equals(null)) {
- writer.write("null");
- } else if (value instanceof JSONObject) {
- ((JSONObject) value).write(writer, indentFactor, indent);
- } else if (value instanceof JSONArray) {
- ((JSONArray) value).write(writer, indentFactor, indent);
- } else if (value instanceof Map) {
- new JSONObject((Map) value).write(writer, indentFactor, indent);
- } else if (value instanceof Collection) {
- new JSONArray((Collection) value).write(writer, indentFactor,
- indent);
- } else if (value.getClass().isArray()) {
- new JSONArray(value).write(writer, indentFactor, indent);
- } else if (value instanceof Number) {
- writer.write(numberToString((Number) value));
- } else if (value instanceof Boolean) {
- writer.write(value.toString());
- } else if (value instanceof JSONString) {
- Object o;
- try {
- o = ((JSONString) value).toJSONString();
- } catch (Exception e) {
- throw new JSONException(e);
- }
- writer.write(o != null ? o.toString() : quote(value.toString()));
- } else {
- quote(value.toString(), writer);
- }
- return writer;
- }
-
- static final void indent(Writer writer, int indent) throws IOException {
- for (int i = 0; i < indent; i += 1) {
- writer.write(' ');
- }
- }
-
- /**
- * Write the contents of the JSONObject as JSON text to a writer. For
- * compactness, no whitespace is added.
- *
- * Warning: This method assumes that the data structure is acyclical.
- *
- * @return The writer.
- * @throws JSONException
- */
- Writer write(Writer writer, int indentFactor, int indent)
- throws JSONException {
- try {
- boolean commanate = false;
- final int length = this.length();
- Iterator keys = this.keys();
- writer.write('{');
-
- if (length == 1) {
- Object key = keys.next();
- writer.write(quote(key.toString()));
- writer.write(':');
- if (indentFactor > 0) {
- writer.write(' ');
- }
- writeValue(writer, this.map.get(key), indentFactor, indent);
- } else if (length != 0) {
- final int newindent = indent + indentFactor;
- while (keys.hasNext()) {
- Object key = keys.next();
- if (commanate) {
- writer.write(',');
- }
- if (indentFactor > 0) {
- writer.write('\n');
- }
- indent(writer, newindent);
- writer.write(quote(key.toString()));
- writer.write(':');
- if (indentFactor > 0) {
- writer.write(' ');
- }
- writeValue(writer, this.map.get(key), indentFactor,
- newindent);
- commanate = true;
- }
- if (indentFactor > 0) {
- writer.write('\n');
- }
- indent(writer, indent);
- }
- writer.write('}');
- return writer;
- } catch (IOException exception) {
- throw new JSONException(exception);
- }
- }
-}
diff --git a/restx-build/src/main/java/restx/build/org/json/JSONString.java b/restx-build/src/main/java/restx/build/org/json/JSONString.java
deleted file mode 100755
index ae2151d81..000000000
--- a/restx-build/src/main/java/restx/build/org/json/JSONString.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package restx.build.org.json;
-/**
- * The JSONString
interface allows a toJSONString()
- * method so that a class can change the behavior of
- * JSONObject.toString()
, JSONArray.toString()
,
- * and JSONWriter.value(
Object)
. The
- * toJSONString
method will be used instead of the default behavior
- * of using the Object's toString()
method and quoting the result.
- */
-public interface JSONString {
- /**
- * The toJSONString
method allows a class to produce its own JSON
- * serialization.
- *
- * @return A strictly syntactically correct JSON text.
- */
- public String toJSONString();
-}
diff --git a/restx-build/src/main/java/restx/build/org/json/JSONTokener.java b/restx-build/src/main/java/restx/build/org/json/JSONTokener.java
deleted file mode 100644
index 15bf5d8f0..000000000
--- a/restx-build/src/main/java/restx/build/org/json/JSONTokener.java
+++ /dev/null
@@ -1,446 +0,0 @@
-package restx.build.org.json;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.io.StringReader;
-
-/*
-Copyright (c) 2002 JSON.org
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-The Software shall be used for Good, not Evil.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-*/
-
-/**
- * A JSONTokener takes a source string and extracts characters and tokens from
- * it. It is used by the JSONObject and JSONArray constructors to parse
- * JSON source strings.
- * @author JSON.org
- * @version 2012-02-16
- */
-public class JSONTokener {
-
- private long character;
- private boolean eof;
- private long index;
- private long line;
- private char previous;
- private Reader reader;
- private boolean usePrevious;
-
-
- /**
- * Construct a JSONTokener from a Reader.
- *
- * @param reader A reader.
- */
- public JSONTokener(Reader reader) {
- this.reader = reader.markSupported()
- ? reader
- : new BufferedReader(reader);
- this.eof = false;
- this.usePrevious = false;
- this.previous = 0;
- this.index = 0;
- this.character = 1;
- this.line = 1;
- }
-
-
- /**
- * Construct a JSONTokener from an InputStream.
- */
- public JSONTokener(InputStream inputStream) throws JSONException {
- this(new InputStreamReader(inputStream));
- }
-
-
- /**
- * Construct a JSONTokener from a string.
- *
- * @param s A source string.
- */
- public JSONTokener(String s) {
- this(new StringReader(s));
- }
-
-
- /**
- * Back up one character. This provides a sort of lookahead capability,
- * so that you can test for a digit or letter before attempting to parse
- * the next number or identifier.
- */
- public void back() throws JSONException {
- if (this.usePrevious || this.index <= 0) {
- throw new JSONException("Stepping back two steps is not supported");
- }
- this.index -= 1;
- this.character -= 1;
- this.usePrevious = true;
- this.eof = false;
- }
-
-
- /**
- * Get the hex value of a character (base16).
- * @param c A character between '0' and '9' or between 'A' and 'F' or
- * between 'a' and 'f'.
- * @return An int between 0 and 15, or -1 if c was not a hex digit.
- */
- public static int dehexchar(char c) {
- if (c >= '0' && c <= '9') {
- return c - '0';
- }
- if (c >= 'A' && c <= 'F') {
- return c - ('A' - 10);
- }
- if (c >= 'a' && c <= 'f') {
- return c - ('a' - 10);
- }
- return -1;
- }
-
- public boolean end() {
- return this.eof && !this.usePrevious;
- }
-
-
- /**
- * Determine if the source string still contains characters that next()
- * can consume.
- * @return true if not yet at the end of the source.
- */
- public boolean more() throws JSONException {
- this.next();
- if (this.end()) {
- return false;
- }
- this.back();
- return true;
- }
-
-
- /**
- * Get the next character in the source string.
- *
- * @return The next character, or 0 if past the end of the source string.
- */
- public char next() throws JSONException {
- int c;
- if (this.usePrevious) {
- this.usePrevious = false;
- c = this.previous;
- } else {
- try {
- c = this.reader.read();
- } catch (IOException exception) {
- throw new JSONException(exception);
- }
-
- if (c <= 0) { // End of stream
- this.eof = true;
- c = 0;
- }
- }
- this.index += 1;
- if (this.previous == '\r') {
- this.line += 1;
- this.character = c == '\n' ? 0 : 1;
- } else if (c == '\n') {
- this.line += 1;
- this.character = 0;
- } else {
- this.character += 1;
- }
- this.previous = (char) c;
- return this.previous;
- }
-
-
- /**
- * Consume the next character, and check that it matches a specified
- * character.
- * @param c The character to match.
- * @return The character.
- * @throws JSONException if the character does not match.
- */
- public char next(char c) throws JSONException {
- char n = this.next();
- if (n != c) {
- throw this.syntaxError("Expected '" + c + "' and instead saw '" +
- n + "'");
- }
- return n;
- }
-
-
- /**
- * Get the next n characters.
- *
- * @param n The number of characters to take.
- * @return A string of n characters.
- * @throws JSONException
- * Substring bounds error if there are not
- * n characters remaining in the source string.
- */
- public String next(int n) throws JSONException {
- if (n == 0) {
- return "";
- }
-
- char[] chars = new char[n];
- int pos = 0;
-
- while (pos < n) {
- chars[pos] = this.next();
- if (this.end()) {
- throw this.syntaxError("Substring bounds error");
- }
- pos += 1;
- }
- return new String(chars);
- }
-
-
- /**
- * Get the next char in the string, skipping whitespace.
- * @throws JSONException
- * @return A character, or 0 if there are no more characters.
- */
- public char nextClean() throws JSONException {
- for (;;) {
- char c = this.next();
- if (c == 0 || c > ' ') {
- return c;
- }
- }
- }
-
-
- /**
- * Return the characters up to the next close quote character.
- * Backslash processing is done. The formal JSON format does not
- * allow strings in single quotes, but an implementation is allowed to
- * accept them.
- * @param quote The quoting character, either
- * "
(double quote) or
- * '
(single quote).
- * @return A String.
- * @throws JSONException Unterminated string.
- */
- public String nextString(char quote) throws JSONException {
- char c;
- StringBuffer sb = new StringBuffer();
- for (;;) {
- c = this.next();
- switch (c) {
- case 0:
- case '\n':
- case '\r':
- throw this.syntaxError("Unterminated string");
- case '\\':
- c = this.next();
- switch (c) {
- case 'b':
- sb.append('\b');
- break;
- case 't':
- sb.append('\t');
- break;
- case 'n':
- sb.append('\n');
- break;
- case 'f':
- sb.append('\f');
- break;
- case 'r':
- sb.append('\r');
- break;
- case 'u':
- sb.append((char)Integer.parseInt(this.next(4), 16));
- break;
- case '"':
- case '\'':
- case '\\':
- case '/':
- sb.append(c);
- break;
- default:
- throw this.syntaxError("Illegal escape.");
- }
- break;
- default:
- if (c == quote) {
- return sb.toString();
- }
- sb.append(c);
- }
- }
- }
-
-
- /**
- * Get the text up but not including the specified character or the
- * end of line, whichever comes first.
- * @param delimiter A delimiter character.
- * @return A string.
- */
- public String nextTo(char delimiter) throws JSONException {
- StringBuffer sb = new StringBuffer();
- for (;;) {
- char c = this.next();
- if (c == delimiter || c == 0 || c == '\n' || c == '\r') {
- if (c != 0) {
- this.back();
- }
- return sb.toString().trim();
- }
- sb.append(c);
- }
- }
-
-
- /**
- * Get the text up but not including one of the specified delimiter
- * characters or the end of line, whichever comes first.
- * @param delimiters A set of delimiter characters.
- * @return A string, trimmed.
- */
- public String nextTo(String delimiters) throws JSONException {
- char c;
- StringBuffer sb = new StringBuffer();
- for (;;) {
- c = this.next();
- if (delimiters.indexOf(c) >= 0 || c == 0 ||
- c == '\n' || c == '\r') {
- if (c != 0) {
- this.back();
- }
- return sb.toString().trim();
- }
- sb.append(c);
- }
- }
-
-
- /**
- * Get the next value. The value can be a Boolean, Double, Integer,
- * JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object.
- * @throws JSONException If syntax error.
- *
- * @return An object.
- */
- public Object nextValue() throws JSONException {
- char c = this.nextClean();
- String string;
-
- switch (c) {
- case '"':
- case '\'':
- return this.nextString(c);
- case '{':
- this.back();
- return new JSONObject(this);
- case '[':
- this.back();
- return new JSONArray(this);
- }
-
- /*
- * Handle unquoted text. This could be the values true, false, or
- * null, or it can be a number. An implementation (such as this one)
- * is allowed to also accept non-standard forms.
- *
- * Accumulate characters until we reach the end of the text or a
- * formatting character.
- */
-
- StringBuffer sb = new StringBuffer();
- while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) {
- sb.append(c);
- c = this.next();
- }
- this.back();
-
- string = sb.toString().trim();
- if ("".equals(string)) {
- throw this.syntaxError("Missing value");
- }
- return JSONObject.stringToValue(string);
- }
-
-
- /**
- * Skip characters until the next character is the requested character.
- * If the requested character is not found, no characters are skipped.
- * @param to A character to skip to.
- * @return The requested character, or zero if the requested character
- * is not found.
- */
- public char skipTo(char to) throws JSONException {
- char c;
- try {
- long startIndex = this.index;
- long startCharacter = this.character;
- long startLine = this.line;
- this.reader.mark(1000000);
- do {
- c = this.next();
- if (c == 0) {
- this.reader.reset();
- this.index = startIndex;
- this.character = startCharacter;
- this.line = startLine;
- return c;
- }
- } while (c != to);
- } catch (IOException exc) {
- throw new JSONException(exc);
- }
-
- this.back();
- return c;
- }
-
-
- /**
- * Make a JSONException to signal a syntax error.
- *
- * @param message The error message.
- * @return A JSONException object, suitable for throwing
- */
- public JSONException syntaxError(String message) {
- return new JSONException(message + this.toString());
- }
-
-
- /**
- * Make a printable string of this JSONTokener.
- *
- * @return " at {index} [character {character} line {line}]"
- */
- public String toString() {
- return " at " + this.index + " [character " + this.character + " line " +
- this.line + "]";
- }
-}
diff --git a/restx-build/src/main/java/restx/build/org/json/None.java b/restx-build/src/main/java/restx/build/org/json/None.java
deleted file mode 100644
index 33bcd28f7..000000000
--- a/restx-build/src/main/java/restx/build/org/json/None.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package restx.build.org.json;
-
-public interface None {
- /**
- * Negative One
- */
- public static final int none = -1;
-
-}
diff --git a/restx-build/src/main/java/restx/build/org/json/README b/restx-build/src/main/java/restx/build/org/json/README
deleted file mode 100755
index b77c71a21..000000000
--- a/restx-build/src/main/java/restx/build/org/json/README
+++ /dev/null
@@ -1,68 +0,0 @@
-JSON in Java [package org.json]
-
-Douglas Crockford
-douglas@crockford.com
-
-2011-02-02
-
-
-JSON is a light-weight, language independent, data interchange format.
-See http://www.JSON.org/
-
-The files in this package implement JSON encoders/decoders in Java.
-It also includes the capability to convert between JSON and XML, HTTP
-headers, Cookies, and CDL.
-
-This is a reference implementation. There is a large number of JSON packages
-in Java. Perhaps someday the Java community will standardize on one. Until
-then, choose carefully.
-
-The license includes this restriction: "The software shall be used for good,
-not evil." If your conscience cannot live with that, then choose a different
-package.
-
-The package compiles on Java 1.2 thru Java 1.4.
-
-
-JSONObject.java: The JSONObject can parse text from a String or a JSONTokener
-to produce a map-like object. The object provides methods for manipulating its
-contents, and for producing a JSON compliant object serialization.
-
-JSONArray.java: The JSONObject can parse text from a String or a JSONTokener
-to produce a vector-like object. The object provides methods for manipulating
-its contents, and for producing a JSON compliant array serialization.
-
-JSONTokener.java: The JSONTokener breaks a text into a sequence of individual
-tokens. It can be constructed from a String, Reader, or InputStream.
-
-JSONException.java: The JSONException is the standard exception type thrown
-by this package.
-
-
-JSONString.java: The JSONString interface requires a toJSONString method,
-allowing an object to provide its own serialization.
-
-JSONStringer.java: The JSONStringer provides a convenient facility for
-building JSON strings.
-
-JSONWriter.java: The JSONWriter provides a convenient facility for building
-JSON text through a writer.
-
-
-CDL.java: CDL provides support for converting between JSON and comma
-delimited lists.
-
-Cookie.java: Cookie provides support for converting between JSON and cookies.
-
-CookieList.java: CookieList provides support for converting between JSON and
-cookie lists.
-
-HTTP.java: HTTP provides support for converting between JSON and HTTP headers.
-
-HTTPTokener.java: HTTPTokener extends JSONTokener for parsing HTTP headers.
-
-XML.java: XML provides support for converting between JSON and XML.
-
-JSONML.java: JSONML provides support for converting between JSONML and XML.
-
-XMLTokener.java: XMLTokener extends JSONTokener for parsing XML text.
diff --git a/restx-build/src/main/java/restx/build/org/json/XML.java b/restx-build/src/main/java/restx/build/org/json/XML.java
deleted file mode 100755
index 226ba5f29..000000000
--- a/restx-build/src/main/java/restx/build/org/json/XML.java
+++ /dev/null
@@ -1,508 +0,0 @@
-package restx.build.org.json;
-
-/*
-Copyright (c) 2002 JSON.org
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-The Software shall be used for Good, not Evil.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-*/
-
-import java.util.Iterator;
-
-
-/**
- * This provides static methods to convert an XML text into a JSONObject,
- * and to covert a JSONObject into an XML text.
- * @author JSON.org
- * @version 2012-10-26
- */
-public class XML {
-
- /** The Character '&'. */
- public static final Character AMP = new Character('&');
-
- /** The Character '''. */
- public static final Character APOS = new Character('\'');
-
- /** The Character '!'. */
- public static final Character BANG = new Character('!');
-
- /** The Character '='. */
- public static final Character EQ = new Character('=');
-
- /** The Character '>'. */
- public static final Character GT = new Character('>');
-
- /** The Character '<'. */
- public static final Character LT = new Character('<');
-
- /** The Character '?'. */
- public static final Character QUEST = new Character('?');
-
- /** The Character '"'. */
- public static final Character QUOT = new Character('"');
-
- /** The Character '/'. */
- public static final Character SLASH = new Character('/');
-
- /**
- * Replace special characters with XML escapes:
- *
- * & (ampersand) is replaced by &
- * < (less than) is replaced by <
- * > (greater than) is replaced by >
- * " (double quote) is replaced by "
- *
- * @param string The string to be escaped.
- * @return The escaped string.
- */
- public static String escape(String string) {
- StringBuffer sb = new StringBuffer();
- for (int i = 0, length = string.length(); i < length; i++) {
- char c = string.charAt(i);
- switch (c) {
- case '&':
- sb.append("&");
- break;
- case '<':
- sb.append("<");
- break;
- case '>':
- sb.append(">");
- break;
- case '"':
- sb.append(""");
- break;
- case '\'':
- sb.append("'");
- break;
- default:
- sb.append(c);
- }
- }
- return sb.toString();
- }
-
- /**
- * Throw an exception if the string contains whitespace.
- * Whitespace is not allowed in tagNames and attributes.
- * @param string
- * @throws JSONException
- */
- public static void noSpace(String string) throws JSONException {
- int i, length = string.length();
- if (length == 0) {
- throw new JSONException("Empty string.");
- }
- for (i = 0; i < length; i += 1) {
- if (Character.isWhitespace(string.charAt(i))) {
- throw new JSONException("'" + string +
- "' contains a space character.");
- }
- }
- }
-
- /**
- * Scan the content following the named tag, attaching it to the context.
- * @param x The XMLTokener containing the source string.
- * @param context The JSONObject that will include the new material.
- * @param name The tag name.
- * @return true if the close tag is processed.
- * @throws JSONException
- */
- private static boolean parse(XMLTokener x, JSONObject context,
- String name) throws JSONException {
- char c;
- int i;
- JSONObject jsonobject = null;
- String string;
- String tagName;
- Object token;
-
-// Test for and skip past these forms:
-//
-//
-//
-// ... ?>
-// Report errors for these forms:
-// <>
-// <=
-// <<
-
- token = x.nextToken();
-
-// ");
- return false;
- }
- x.back();
- } else if (c == '[') {
- token = x.nextToken();
- if ("CDATA".equals(token)) {
- if (x.next() == '[') {
- string = x.nextCDATA();
- if (string.length() > 0) {
- context.accumulate("content", string);
- }
- return false;
- }
- }
- throw x.syntaxError("Expected 'CDATA['");
- }
- i = 1;
- do {
- token = x.nextMeta();
- if (token == null) {
- throw x.syntaxError("Missing '>' after ' 0);
- return false;
- } else if (token == QUEST) {
-
-//
-
- x.skipPast("?>");
- return false;
- } else if (token == SLASH) {
-
-// Close tag
-
- token = x.nextToken();
- if (name == null) {
- throw x.syntaxError("Mismatched close tag " + token);
- }
- if (!token.equals(name)) {
- throw x.syntaxError("Mismatched " + name + " and " + token);
- }
- if (x.nextToken() != GT) {
- throw x.syntaxError("Misshaped close tag");
- }
- return true;
-
- } else if (token instanceof Character) {
- throw x.syntaxError("Misshaped tag");
-
-// Open tag <
-
- } else {
- tagName = (String)token;
- token = null;
- jsonobject = new JSONObject();
- for (;;) {
- if (token == null) {
- token = x.nextToken();
- }
-
-// attribute = value
-
- if (token instanceof String) {
- string = (String)token;
- token = x.nextToken();
- if (token == EQ) {
- token = x.nextToken();
- if (!(token instanceof String)) {
- throw x.syntaxError("Missing value");
- }
- jsonobject.accumulate(string,
- XML.stringToValue((String)token));
- token = null;
- } else {
- jsonobject.accumulate(string, "");
- }
-
-// Empty tag <.../>
-
- } else if (token == SLASH) {
- if (x.nextToken() != GT) {
- throw x.syntaxError("Misshaped tag");
- }
- if (jsonobject.length() > 0) {
- context.accumulate(tagName, jsonobject);
- } else {
- context.accumulate(tagName, "");
- }
- return false;
-
-// Content, between <...> and
-
- } else if (token == GT) {
- for (;;) {
- token = x.nextContent();
- if (token == null) {
- if (tagName != null) {
- throw x.syntaxError("Unclosed tag " + tagName);
- }
- return false;
- } else if (token instanceof String) {
- string = (String)token;
- if (string.length() > 0) {
- jsonobject.accumulate("content",
- XML.stringToValue(string));
- }
-
-// Nested element
-
- } else if (token == LT) {
- if (parse(x, jsonobject, tagName)) {
- if (jsonobject.length() == 0) {
- context.accumulate(tagName, "");
- } else if (jsonobject.length() == 1 &&
- jsonobject.opt("content") != null) {
- context.accumulate(tagName,
- jsonobject.opt("content"));
- } else {
- context.accumulate(tagName, jsonobject);
- }
- return false;
- }
- }
- }
- } else {
- throw x.syntaxError("Misshaped tag");
- }
- }
- }
- }
-
-
- /**
- * Try to convert a string into a number, boolean, or null. If the string
- * can't be converted, return the string. This is much less ambitious than
- * JSONObject.stringToValue, especially because it does not attempt to
- * convert plus forms, octal forms, hex forms, or E forms lacking decimal
- * points.
- * @param string A String.
- * @return A simple JSON value.
- */
- public static Object stringToValue(String string) {
- if ("".equals(string)) {
- return string;
- }
- if ("true".equalsIgnoreCase(string)) {
- return Boolean.TRUE;
- }
- if ("false".equalsIgnoreCase(string)) {
- return Boolean.FALSE;
- }
- if ("null".equalsIgnoreCase(string)) {
- return JSONObject.NULL;
- }
- if ("0".equals(string)) {
- return new Integer(0);
- }
-
-// If it might be a number, try converting it. If that doesn't work,
-// return the string.
-
- try {
- char initial = string.charAt(0);
- boolean negative = false;
- if (initial == '-') {
- initial = string.charAt(1);
- negative = true;
- }
- if (initial == '0' && string.charAt(negative ? 2 : 1) == '0') {
- return string;
- }
- if ((initial >= '0' && initial <= '9')) {
- if (string.indexOf('.') >= 0) {
- return Double.valueOf(string);
- } else if (string.indexOf('e') < 0 && string.indexOf('E') < 0) {
- Long myLong = new Long(string);
- if (myLong.longValue() == myLong.intValue()) {
- return new Integer(myLong.intValue());
- } else {
- return myLong;
- }
- }
- }
- } catch (Exception ignore) {
- }
- return string;
- }
-
-
- /**
- * Convert a well-formed (but not necessarily valid) XML string into a
- * JSONObject. Some information may be lost in this transformation
- * because JSON is a data format and XML is a document format. XML uses
- * elements, attributes, and content text, while JSON uses unordered
- * collections of name/value pairs and arrays of values. JSON does not
- * does not like to distinguish between elements and attributes.
- * Sequences of similar elements are represented as JSONArrays. Content
- * text may be placed in a "content" member. Comments, prologs, DTDs, and
- * <[ [ ]]>
are ignored.
- * @param string The source string.
- * @return A JSONObject containing the structured data from the XML string.
- * @throws JSONException
- */
- public static JSONObject toJSONObject(String string) throws JSONException {
- JSONObject jo = new JSONObject();
- XMLTokener x = new XMLTokener(string);
- while (x.more() && x.skipPast("<")) {
- parse(x, jo, null);
- }
- return jo;
- }
-
-
- /**
- * Convert a JSONObject into a well-formed, element-normal XML string.
- * @param object A JSONObject.
- * @return A string.
- * @throws JSONException
- */
- public static String toString(Object object) throws JSONException {
- return toString(object, null);
- }
-
-
- /**
- * Convert a JSONObject into a well-formed, element-normal XML string.
- * @param object A JSONObject.
- * @param tagName The optional name of the enclosing tag.
- * @return A string.
- * @throws JSONException
- */
- public static String toString(Object object, String tagName)
- throws JSONException {
- StringBuffer sb = new StringBuffer();
- int i;
- JSONArray ja;
- JSONObject jo;
- String key;
- Iterator keys;
- int length;
- String string;
- Object value;
- if (object instanceof JSONObject) {
-
-// Emit
-
- if (tagName != null) {
- sb.append('<');
- sb.append(tagName);
- sb.append('>');
- }
-
-// Loop thru the keys.
-
- jo = (JSONObject)object;
- keys = jo.keys();
- while (keys.hasNext()) {
- key = keys.next().toString();
- value = jo.opt(key);
- if (value == null) {
- value = "";
- }
- if (value instanceof String) {
- string = (String)value;
- } else {
- string = null;
- }
-
-// Emit content in body
-
- if ("content".equals(key)) {
- if (value instanceof JSONArray) {
- ja = (JSONArray)value;
- length = ja.length();
- for (i = 0; i < length; i += 1) {
- if (i > 0) {
- sb.append('\n');
- }
- sb.append(escape(ja.get(i).toString()));
- }
- } else {
- sb.append(escape(value.toString()));
- }
-
-// Emit an array of similar keys
-
- } else if (value instanceof JSONArray) {
- ja = (JSONArray)value;
- length = ja.length();
- for (i = 0; i < length; i += 1) {
- value = ja.get(i);
- if (value instanceof JSONArray) {
- sb.append('<');
- sb.append(key);
- sb.append('>');
- sb.append(toString(value));
- sb.append("");
- sb.append(key);
- sb.append('>');
- } else {
- sb.append(toString(value, key));
- }
- }
- } else if ("".equals(value)) {
- sb.append('<');
- sb.append(key);
- sb.append("/>");
-
-// Emit a new tag
-
- } else {
- sb.append(toString(value, key));
- }
- }
- if (tagName != null) {
-
-// Emit the close tag
-
- sb.append("");
- sb.append(tagName);
- sb.append('>');
- }
- return sb.toString();
-
-// XML does not have good support for arrays. If an array appears in a place
-// where XML is lacking, synthesize an element.
-
- } else {
- if (object.getClass().isArray()) {
- object = new JSONArray(object);
- }
- if (object instanceof JSONArray) {
- ja = (JSONArray)object;
- length = ja.length();
- for (i = 0; i < length; i += 1) {
- sb.append(toString(ja.opt(i), tagName == null ? "array" : tagName));
- }
- return sb.toString();
- } else {
- string = (object == null) ? "null" : escape(object.toString());
- return (tagName == null) ? "\"" + string + "\"" :
- (string.length() == 0) ? "<" + tagName + "/>" :
- "<" + tagName + ">" + string + "" + tagName + ">";
- }
- }
- }
-}
diff --git a/restx-build/src/main/java/restx/build/org/json/XMLTokener.java b/restx-build/src/main/java/restx/build/org/json/XMLTokener.java
deleted file mode 100755
index 88b9b48fb..000000000
--- a/restx-build/src/main/java/restx/build/org/json/XMLTokener.java
+++ /dev/null
@@ -1,366 +0,0 @@
-package restx.build.org.json;
-
-/*
-Copyright (c) 2002 JSON.org
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-The Software shall be used for Good, not Evil.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-*/
-
-/**
- * The XMLTokener extends the JSONTokener to provide additional methods
- * for the parsing of XML texts.
- * @author JSON.org
- * @version 2012-11-13
- */
-@SuppressWarnings("unchecked")
-public class XMLTokener extends JSONTokener {
-
-
- /** The table of entity values. It initially contains Character values for
- * amp, apos, gt, lt, quot.
- */
- public static final java.util.HashMap entity;
-
- static {
- entity = new java.util.HashMap(8);
- entity.put("amp", XML.AMP);
- entity.put("apos", XML.APOS);
- entity.put("gt", XML.GT);
- entity.put("lt", XML.LT);
- entity.put("quot", XML.QUOT);
- }
-
- /**
- * Construct an XMLTokener from a string.
- * @param s A source string.
- */
- public XMLTokener(String s) {
- super(s);
- }
-
- /**
- * Get the text in the CDATA block.
- * @return The string up to the ]]>
.
- * @throws JSONException If the ]]>
is not found.
- */
- public String nextCDATA() throws JSONException {
- char c;
- int i;
- StringBuffer sb = new StringBuffer();
- for (;;) {
- c = next();
- if (end()) {
- throw syntaxError("Unclosed CDATA");
- }
- sb.append(c);
- i = sb.length() - 3;
- if (i >= 0 && sb.charAt(i) == ']' &&
- sb.charAt(i + 1) == ']' && sb.charAt(i + 2) == '>') {
- sb.setLength(i);
- return sb.toString();
- }
- }
- }
-
-
- /**
- * Get the next XML outer token, trimming whitespace. There are two kinds
- * of tokens: the '<' character which begins a markup tag, and the content
- * text between markup tags.
- *
- * @return A string, or a '<' Character, or null if there is no more
- * source text.
- * @throws JSONException
- */
- public Object nextContent() throws JSONException {
- char c;
- StringBuffer sb;
- do {
- c = next();
- } while (Character.isWhitespace(c));
- if (c == 0) {
- return null;
- }
- if (c == '<') {
- return XML.LT;
- }
- sb = new StringBuffer();
- for (;;) {
- if (c == '<' || c == 0) {
- back();
- return sb.toString().trim();
- }
- if (c == '&') {
- sb.append(nextEntity(c));
- } else {
- sb.append(c);
- }
- c = next();
- }
- }
-
-
- /**
- * Return the next entity. These entities are translated to Characters:
- * & ' > < "
.
- * @param ampersand An ampersand character.
- * @return A Character or an entity String if the entity is not recognized.
- * @throws JSONException If missing ';' in XML entity.
- */
- public Object nextEntity(char ampersand) throws JSONException {
- StringBuffer sb = new StringBuffer();
- for (;;) {
- char c = next();
- if (Character.isLetterOrDigit(c) || c == '#') {
- sb.append(Character.toLowerCase(c));
- } else if (c == ';') {
- break;
- } else {
- throw syntaxError("Missing ';' in XML entity: &" + sb);
- }
- }
- String string = sb.toString();
- Object object = entity.get(string);
- return object != null ? object : ampersand + string + ";";
- }
-
-
- /**
- * Returns the next XML meta token. This is used for skipping over <!...>
- * and <?...?> structures.
- * @return Syntax characters (< > / = ! ?
) are returned as
- * Character, and strings and names are returned as Boolean. We don't care
- * what the values actually are.
- * @throws JSONException If a string is not properly closed or if the XML
- * is badly structured.
- */
- public Object nextMeta() throws JSONException {
- char c;
- char q;
- do {
- c = next();
- } while (Character.isWhitespace(c));
- switch (c) {
- case 0:
- throw syntaxError("Misshaped meta tag");
- case '<':
- return XML.LT;
- case '>':
- return XML.GT;
- case '/':
- return XML.SLASH;
- case '=':
- return XML.EQ;
- case '!':
- return XML.BANG;
- case '?':
- return XML.QUEST;
- case '"':
- case '\'':
- q = c;
- for (;;) {
- c = next();
- if (c == 0) {
- throw syntaxError("Unterminated string");
- }
- if (c == q) {
- return Boolean.TRUE;
- }
- }
- default:
- for (;;) {
- c = next();
- if (Character.isWhitespace(c)) {
- return Boolean.TRUE;
- }
- switch (c) {
- case 0:
- case '<':
- case '>':
- case '/':
- case '=':
- case '!':
- case '?':
- case '"':
- case '\'':
- back();
- return Boolean.TRUE;
- }
- }
- }
- }
-
-
- /**
- * Get the next XML Token. These tokens are found inside of angle
- * brackets. It may be one of these characters: / > = ! ?
or it
- * may be a string wrapped in single quotes or double quotes, or it may be a
- * name.
- * @return a String or a Character.
- * @throws JSONException If the XML is not well formed.
- */
- public Object nextToken() throws JSONException {
- char c;
- char q;
- StringBuffer sb;
- do {
- c = next();
- } while (Character.isWhitespace(c));
- switch (c) {
- case 0:
- throw syntaxError("Misshaped element");
- case '<':
- throw syntaxError("Misplaced '<'");
- case '>':
- return XML.GT;
- case '/':
- return XML.SLASH;
- case '=':
- return XML.EQ;
- case '!':
- return XML.BANG;
- case '?':
- return XML.QUEST;
-
-// Quoted string
-
- case '"':
- case '\'':
- q = c;
- sb = new StringBuffer();
- for (;;) {
- c = next();
- if (c == 0) {
- throw syntaxError("Unterminated string");
- }
- if (c == q) {
- return sb.toString();
- }
- if (c == '&') {
- sb.append(nextEntity(c));
- } else {
- sb.append(c);
- }
- }
- default:
-
-// Name
-
- sb = new StringBuffer();
- for (;;) {
- sb.append(c);
- c = next();
- if (Character.isWhitespace(c)) {
- return sb.toString();
- }
- switch (c) {
- case 0:
- return sb.toString();
- case '>':
- case '/':
- case '=':
- case '!':
- case '?':
- case '[':
- case ']':
- back();
- return sb.toString();
- case '<':
- case '"':
- case '\'':
- throw syntaxError("Bad character in a name");
- }
- }
- }
- }
-
-
- /**
- * Skip characters until past the requested string.
- * If it is not found, we are left at the end of the source with a result of false.
- * @param to A string to skip past.
- * @throws JSONException
- */
- public boolean skipPast(String to) throws JSONException {
- boolean b;
- char c;
- int i;
- int j;
- int offset = 0;
- int length = to.length();
- char[] circle = new char[length];
-
- /*
- * First fill the circle buffer with as many characters as are in the
- * to string. If we reach an early end, bail.
- */
-
- for (i = 0; i < length; i += 1) {
- c = next();
- if (c == 0) {
- return false;
- }
- circle[i] = c;
- }
-
- /* We will loop, possibly for all of the remaining characters. */
-
- for (;;) {
- j = offset;
- b = true;
-
- /* Compare the circle buffer with the to string. */
-
- for (i = 0; i < length; i += 1) {
- if (circle[j] != to.charAt(i)) {
- b = false;
- break;
- }
- j += 1;
- if (j >= length) {
- j -= length;
- }
- }
-
- /* If we exit the loop with b intact, then victory is ours. */
-
- if (b) {
- return true;
- }
-
- /* Get the next character. If there isn't one, then defeat is ours. */
-
- c = next();
- if (c == 0) {
- return false;
- }
- /*
- * Shove the character in the circle buffer and advance the
- * circle offset. The offset is mod n.
- */
- circle[offset] = c;
- offset += 1;
- if (offset >= length) {
- offset -= length;
- }
- }
- }
-}
diff --git a/restx-build/src/main/resources/restx/build/fragments/maven/annotation-processing-disable.xml b/restx-build/src/main/resources/restx/build/fragments/maven/annotation-processing-disable.xml
deleted file mode 100644
index 30760718a..000000000
--- a/restx-build/src/main/resources/restx/build/fragments/maven/annotation-processing-disable.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
- org.apache.maven.plugins
- maven-compiler-plugin
-
- -proc:none
-
-
diff --git a/restx-build/src/main/resources/restx/build/fragments/maven/copy-dependencies.xml b/restx-build/src/main/resources/restx/build/fragments/maven/copy-dependencies.xml
deleted file mode 100644
index 772bf7fba..000000000
--- a/restx-build/src/main/resources/restx/build/fragments/maven/copy-dependencies.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
- maven-dependency-plugin
-
-
- copy-dependencies
- install
-
- copy-dependencies
-
-
- compile
- runtime
- test
-
-
-
-
diff --git a/restx-build/src/main/resources/restx/build/fragments/maven/custom-war-resources.xml b/restx-build/src/main/resources/restx/build/fragments/maven/custom-war-resources.xml
deleted file mode 100644
index 35f2e1b00..000000000
--- a/restx-build/src/main/resources/restx/build/fragments/maven/custom-war-resources.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
- org.apache.maven.plugins
- maven-war-plugin
-
-
-
-
- ${project.war.resources.directory}
-
-
-
-
diff --git a/restx-build/src/main/resources/restx/build/fragments/maven/jar-main-class.xml b/restx-build/src/main/resources/restx/build/fragments/maven/jar-main-class.xml
deleted file mode 100644
index 33a25db9c..000000000
--- a/restx-build/src/main/resources/restx/build/fragments/maven/jar-main-class.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
- org.apache.maven.plugins
- maven-jar-plugin
-
-
-
- ${project.main.classname}
-
-
-
-
diff --git a/restx-build/src/main/resources/restx/build/fragments/maven/java-agent.xml b/restx-build/src/main/resources/restx/build/fragments/maven/java-agent.xml
deleted file mode 100644
index 4ae15e1cd..000000000
--- a/restx-build/src/main/resources/restx/build/fragments/maven/java-agent.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-
- org.apache.maven.plugins
- maven-compiler-plugin
-
- -proc:none
-
-
-
- org.apache.maven.plugins
- maven-jar-plugin
-
-
-
- ${project.premain.classname}
- ${project.agent.can-redefine-classes}
- ${project.agent.can-retransform-classes}
- ${project.agent.can-set-native-method-prefix}
-
-
-
-
diff --git a/restx-build/src/main/resources/restx/build/fragments/maven/javadoc-apidoclet.xml b/restx-build/src/main/resources/restx/build/fragments/maven/javadoc-apidoclet.xml
deleted file mode 100644
index 74fcfa634..000000000
--- a/restx-build/src/main/resources/restx/build/fragments/maven/javadoc-apidoclet.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
- org.apache.maven.plugins
- maven-javadoc-plugin
-
-
- attach-docs
-
- prepare-package
-
- jar
-
-
-
-
-
- restx.apidocs.doclet.ApidocsDoclet
-
- io.restx
- restx-apidocs-doclet
- ${restx.version}
-
- -restx-target-dir ${project.basedir}/target/classes
-
-
diff --git a/restx-build/src/main/resources/restx/build/fragments/maven/testing-build-shell.xml b/restx-build/src/main/resources/restx/build/fragments/maven/testing-build-shell.xml
deleted file mode 100644
index 78e9fc08c..000000000
--- a/restx-build/src/main/resources/restx/build/fragments/maven/testing-build-shell.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
-
- ${project.basedir}/../
- 10
-
-
-
diff --git a/restx-build/src/main/resources/restx/build/fragments/maven/uber-jar.xml b/restx-build/src/main/resources/restx/build/fragments/maven/uber-jar.xml
deleted file mode 100644
index cfaf983ce..000000000
--- a/restx-build/src/main/resources/restx/build/fragments/maven/uber-jar.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-
- org.apache.maven.plugins
- maven-shade-plugin
-
-
-
-
- ${project.main.classname}
-
-
-
- META-INF/services/restx.factory.FactoryMachine
-
-
-
-
- *:*
-
- META-INF/*.SF
- META-INF/*.DSA
- META-INF/*.RSA
-
-
-
-
-
-
- package
-
- shade
-
-
-
-
diff --git a/restx-build/src/main/resources/restx/build/fragments/maven/war-overlay-resources.xml b/restx-build/src/main/resources/restx/build/fragments/maven/war-overlay-resources.xml
deleted file mode 100644
index 0e73fa303..000000000
--- a/restx-build/src/main/resources/restx/build/fragments/maven/war-overlay-resources.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-
-
- release
-
-
-
- org.apache.maven.plugins
- maven-war-plugin
- 2.6
-
- ${project.war.overlay.artifactId}-full
-
-
- ${project.war.overlay.groupId}
- ${project.war.overlay.artifactId}-ui
- zip
-
-
-
-
-
- org.codehaus.mojo
- build-helper-maven-plugin
- 1.9.1
-
-
- attach-full-war
-
- attach-artifact
-
-
-
-
- ${project.build.directory}${file.separator}${project.war.overlay.artifactId}-full.war
- war
- full
-
-
-
-
-
-
-
-
-
-
- ${project.war.overlay.groupId}
- ${project.war.overlay.artifactId}-ui
- ${project.version}
- zip
-
-
-
-
diff --git a/restx-build/src/test/java/restx/build/GAVTest.java b/restx-build/src/test/java/restx/build/GAVTest.java
deleted file mode 100644
index fb7aabbb3..000000000
--- a/restx-build/src/test/java/restx/build/GAVTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package restx.build;
-
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * User: xavierhanin
- * Date: 4/14/13
- * Time: 2:26 PM
- */
-public class GAVTest {
- @Test
- public void should_parse_and_to_string_be_consistent() throws Exception {
- shouldBeConsistent("fr.4sh.pom-parents:4sh-uberpom:0.8");
- shouldBeConsistent("restx:restx-common:0.2-SNAPSHOT");
- shouldBeConsistent("joda-time:joda-time:${joda-time.version}");
- }
-
- @Test
- public void should_parse_classifier_artifact(){
- shouldBeConsistent("restx:restx-ui:0.2:zip:jdk8");
- shouldBeConsistent("restx:restx-ui:0.2:jar:jdk8");
- }
-
- @Test
- public void should_parse_optional_artifact(){
- shouldBeConsistent("restx:restx-ui:0.2!optional");
- shouldBeConsistent("restx:restx-ui:0.2:zip!optional");
- shouldBeConsistent("restx:restx-ui:0.2:jar:jdk8!optional");
- }
-
- @Test
- public void should_parse_artifact_with_type() throws Exception {
- shouldBeConsistent("restx:restx-ui:0.2:zip");
- }
-
- private void shouldBeConsistent(String gav) {
- assertThat(GAV.parse(gav).toParseableString()).isEqualTo(gav);
- }
-}
diff --git a/restx-build/src/test/java/restx/build/RestxBuildTest.java b/restx-build/src/test/java/restx/build/RestxBuildTest.java
deleted file mode 100644
index 364697fab..000000000
--- a/restx-build/src/test/java/restx/build/RestxBuildTest.java
+++ /dev/null
@@ -1,120 +0,0 @@
-package restx.build;
-
-import org.junit.Test;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.net.URISyntaxException;
-import java.net.URL;
-
-import static org.assertj.core.api.Assertions.*;
-
-/**
- * User: xavierhanin
- * Date: 4/14/13
- * Time: 1:57 PM
- */
-public class RestxBuildTest {
- private RestxJsonSupport json = new RestxJsonSupport();
- private MavenSupport maven = new MavenSupport();
- private IvySupport ivy = new IvySupport();
-
- @Test
- public void should_generate_simple_pom() throws Exception {
- shouldGenerate(json, "Module1.restx.json", maven, "Module1.pom.xml");
- }
-
- @Test
- public void should_generate_simple_pom_with_external_properties() throws Exception {
- shouldGenerate(json, "Module5.restx.json", maven, "Module5.pom.xml");
- }
-
- @Test
- public void should_generate_pom_with_fragment() throws Exception {
- shouldGenerate(json, "Module3.restx.json", maven, "Module3.pom.xml");
- }
-
- @Test
- public void should_generate_pom_with_war() throws Exception {
- shouldGenerate(json, "Module4.restx.json", maven, "Module4.pom.xml");
- }
-
- @Test
- public void should_parse_simple_pom() throws Exception {
- shouldGenerate(maven, "Module1.pom.xml", json, "Module1.restx.json");
- }
-
- @Test
- public void should_parse_simple_pom_with_war() throws Exception {
- shouldGenerate(maven, "Module4.pom.xml", json, "Module4.restx.json");
- }
-
- @Test
- public void should_generate_simple_ivy() throws Exception {
- shouldGenerate(json, "Module1.restx.json", ivy, "Module1.ivy");
- }
-
- @Test
- public void should_generate_simple_ivy_with_external_properties() throws Exception {
- shouldGenerate(json, "Module5.restx.json", ivy, "Module5.ivy");
- }
-
- @Test
- public void should_generate_simple_ivy_war() throws Exception {
- shouldGenerate(json, "Module4.restx.json", ivy, "Module4.ivy");
- }
-
- @Test
- public void should_generate_ivy_with_internal_dep() throws Exception {
- shouldGenerate(json, "Module2.restx.json", ivy, "Module2.ivy");
- }
-
- @Test
- public void should_generate_pom_with_type() throws Exception {
- shouldGenerate(json, "Module6.restx.json", maven, "Module6.pom.xml");
- }
-
- @Test
- public void should_generate_pom_with_merged_fragments() throws Exception {
- shouldGenerate(json, "Module7.restx.json", maven, "Module7.pom.xml");
- }
-
- @Test
- public void should_generate_pom_with_tools_dependency() throws Exception {
- shouldGenerate(json, "Module8.restx.json", maven, "Module8.pom.xml");
- }
-
- @Test
- public void should_generate_pom_with_optional_dependency() throws Exception {
- shouldGenerate(json, "Module9.restx.json", maven, "Module9.pom.xml");
- }
-
- @Test
- public void should_parse_simple_pom_with_optional_dependency() throws Exception {
- shouldGenerate(maven, "Module9.pom.xml", json, "Module9.restx.json");
- }
-
- private void shouldGenerate(RestxBuild.Parser parser, String module, RestxBuild.Generator generator, String expected) throws IOException {
- URL resource = getClass().getResource(module);
- ModuleDescriptor md;
- if (resource.getProtocol().equals("file")) {
- File f;
- try {
- f = new File(resource.toURI());
- } catch(URISyntaxException e) {
- f = new File(resource.getPath());
- }
- md = parser.parse(f.toPath());
- } else {
- try (InputStream stream = resource.openStream()) {
- md = parser.parse(stream);
- }
- }
- StringWriter w = new StringWriter();
- generator.generate(md, w);
- assertThat(w.toString()).isEqualTo(RestxBuildHelper.toString(getClass().getResourceAsStream(expected)));
- }
-
-}
diff --git a/restx-build/src/test/resources/restx/build/Module1.ivy b/restx-build/src/test/resources/restx/build/Module1.ivy
deleted file mode 100644
index 72c4a89f1..000000000
--- a/restx-build/src/test/resources/restx/build/Module1.ivy
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/restx-build/src/test/resources/restx/build/Module1.pom.xml b/restx-build/src/test/resources/restx/build/Module1.pom.xml
deleted file mode 100644
index 6a52910af..000000000
--- a/restx-build/src/test/resources/restx/build/Module1.pom.xml
+++ /dev/null
@@ -1,55 +0,0 @@
-
-
- 4.0.0
-
-
- com.example
- example-parent
- 0.8
-
-
- com.example
- example-common
- 0.2-SNAPSHOT
- jar
- example-common
-
-
- 1.7
- 1.7
- 2.0
- 4.11
-
-
-
-
- com.google.guava
- guava
- 14.0-rc2
-
-
- joda-time
- joda-time
- ${joda-time.version}
-
-
- com.github.spullara.mustache.java
- compiler
- 0.8.10
-
-
- junit
- junit
- ${junit.version}
- test
-
-
- org.easytesting
- fest-assert-core
- 2.0M8
- test
-
-
-
\ No newline at end of file
diff --git a/restx-build/src/test/resources/restx/build/Module1.restx.json b/restx-build/src/test/resources/restx/build/Module1.restx.json
deleted file mode 100644
index 9b7d4b394..000000000
--- a/restx-build/src/test/resources/restx/build/Module1.restx.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "parent": "com.example:example-parent:0.8",
- "module": "com.example:example-common:0.2-SNAPSHOT",
-
- "properties": {
- "java.version": "1.7",
- "joda-time.version": "2.0",
- "junit.version": "4.11"
- },
-
- "dependencies": {
- "compile": [
- "com.google.guava:guava:14.0-rc2",
- "joda-time:joda-time:${joda-time.version}",
- "com.github.spullara.mustache.java:compiler:0.8.10"
- ],
- "test": [
- "junit:junit:${junit.version}",
- "org.easytesting:fest-assert-core:2.0M8"
- ]
- }
-}
\ No newline at end of file
diff --git a/restx-build/src/test/resources/restx/build/Module2.ivy b/restx-build/src/test/resources/restx/build/Module2.ivy
deleted file mode 100644
index b6c841cb5..000000000
--- a/restx-build/src/test/resources/restx/build/Module2.ivy
+++ /dev/null
@@ -1,37 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/restx-build/src/test/resources/restx/build/Module2.restx.json b/restx-build/src/test/resources/restx/build/Module2.restx.json
deleted file mode 100644
index 65184acb4..000000000
--- a/restx-build/src/test/resources/restx/build/Module2.restx.json
+++ /dev/null
@@ -1,34 +0,0 @@
-{
- "parent": "com.example:example-parent:0.8",
- "module": "com.example:example-core:0.2-SNAPSHOT",
-
- "properties": {
- "java.version": "1.7",
- "slf4j-api.version": "1.7.2",
- "jackson.version": "2.1.2"
- },
-
- "dependencies": {
- "compile": [
- "com.fasterxml.jackson.core:jackson-core:${jackson.version}",
- "com.fasterxml.jackson.core:jackson-annotations:${jackson.version}",
- "com.fasterxml.jackson.core:jackson-databind:${jackson.version}",
- "com.fasterxml.jackson.datatype:jackson-datatype-joda:${jackson.version}",
- "com.example:example-factory:${module.version}",
- "javax.inject:javax.inject:1",
- "com.google.guava:guava:14.0-rc2",
- "joda-time:joda-time:2.0",
- "org.slf4j:slf4j-api:${slf4j-api.version}",
- "com.google.code.maven-play-plugin.com.jamonapi:jamon:2.7",
- "org.hibernate:hibernate-validator:5.0.0.Alpha2",
- "org.reflections:reflections:0.9.9-RC1",
- "junit:junit:4.11",
- "org.hamcrest:hamcrest-core:1.3",
- "org.hamcrest:hamcrest-library:1.3",
- "uk.co.datumedge:hamcrest-json:0.2",
- "org.easytesting:fest-assert-core:2.0M8",
- "org.yaml:snakeyaml:1.12",
- "com.github.kevinsawicki:http-request:4.1"
- ]
- }
-}
diff --git a/restx-build/src/test/resources/restx/build/Module3.pom.xml b/restx-build/src/test/resources/restx/build/Module3.pom.xml
deleted file mode 100644
index 2774d80ad..000000000
--- a/restx-build/src/test/resources/restx/build/Module3.pom.xml
+++ /dev/null
@@ -1,66 +0,0 @@
-
-
- 4.0.0
-
-
- com.example
- example-parent
- 0.8
-
-
- com.example
- example-common
- 0.2-SNAPSHOT
- jar
- example-common
-
-
- 1.7
- 1.7
- 2.0
- 4.11
-
-
-
-
- com.google.guava
- guava
- 14.0-rc2
-
-
- joda-time
- joda-time
- ${joda-time.version}
-
-
- com.github.spullara.mustache.java
- compiler
- 0.8.10
-
-
- junit
- junit
- ${junit.version}
- test
-
-
- org.easytesting
- fest-assert-core
- 2.0M8
- test
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
-
- -proc:none
-
-
-
-
-
\ No newline at end of file
diff --git a/restx-build/src/test/resources/restx/build/Module3.restx.json b/restx-build/src/test/resources/restx/build/Module3.restx.json
deleted file mode 100644
index eb6561e71..000000000
--- a/restx-build/src/test/resources/restx/build/Module3.restx.json
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "parent": "com.example:example-parent:0.8",
- "module": "com.example:example-common:0.2-SNAPSHOT",
-
- "properties": {
- "java.version": "1.7",
- "joda-time.version": "2.0",
- "junit.version": "4.11"
- },
-
- "fragments": {
- "maven": [
- "classpath:///restx/build/fragments/maven/annotation-processing-disable.xml"
- ]
- },
-
- "dependencies": {
- "compile": [
- "com.google.guava:guava:14.0-rc2",
- "joda-time:joda-time:${joda-time.version}",
- "com.github.spullara.mustache.java:compiler:0.8.10"
- ],
- "test": [
- "junit:junit:${junit.version}",
- "org.easytesting:fest-assert-core:2.0M8"
- ]
- }
-}
\ No newline at end of file
diff --git a/restx-build/src/test/resources/restx/build/Module4.ivy b/restx-build/src/test/resources/restx/build/Module4.ivy
deleted file mode 100644
index 950e9aef9..000000000
--- a/restx-build/src/test/resources/restx/build/Module4.ivy
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/restx-build/src/test/resources/restx/build/Module4.pom.xml b/restx-build/src/test/resources/restx/build/Module4.pom.xml
deleted file mode 100644
index 3f6b83fa0..000000000
--- a/restx-build/src/test/resources/restx/build/Module4.pom.xml
+++ /dev/null
@@ -1,55 +0,0 @@
-
-
- 4.0.0
-
-
- com.example
- example-parent
- 0.8
-
-
- com.example
- example-common
- 0.2-SNAPSHOT
- war
- example-common
-
-
- 1.7
- 1.7
- 2.0
- 4.11
-
-
-
-
- com.google.guava
- guava
- 14.0-rc2
-
-
- joda-time
- joda-time
- ${joda-time.version}
-
-
- com.github.spullara.mustache.java
- compiler
- 0.8.10
-
-
- junit
- junit
- ${junit.version}
- test
-
-
- org.easytesting
- fest-assert-core
- 2.0M8
- test
-
-
-
\ No newline at end of file
diff --git a/restx-build/src/test/resources/restx/build/Module4.restx.json b/restx-build/src/test/resources/restx/build/Module4.restx.json
deleted file mode 100644
index b19262a44..000000000
--- a/restx-build/src/test/resources/restx/build/Module4.restx.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "parent": "com.example:example-parent:0.8",
- "module": "com.example:example-common:0.2-SNAPSHOT",
- "packaging": "war",
-
- "properties": {
- "java.version": "1.7",
- "joda-time.version": "2.0",
- "junit.version": "4.11"
- },
-
- "dependencies": {
- "compile": [
- "com.google.guava:guava:14.0-rc2",
- "joda-time:joda-time:${joda-time.version}",
- "com.github.spullara.mustache.java:compiler:0.8.10"
- ],
- "test": [
- "junit:junit:${junit.version}",
- "org.easytesting:fest-assert-core:2.0M8"
- ]
- }
-}
\ No newline at end of file
diff --git a/restx-build/src/test/resources/restx/build/Module5.ivy b/restx-build/src/test/resources/restx/build/Module5.ivy
deleted file mode 100644
index 80a7c4cdb..000000000
--- a/restx-build/src/test/resources/restx/build/Module5.ivy
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/restx-build/src/test/resources/restx/build/Module5.pom.xml b/restx-build/src/test/resources/restx/build/Module5.pom.xml
deleted file mode 100644
index 8992b583c..000000000
--- a/restx-build/src/test/resources/restx/build/Module5.pom.xml
+++ /dev/null
@@ -1,61 +0,0 @@
-
-
- 4.0.0
-
-
- com.example
- example-parent
- 0.8
-
-
- com.example
- example-common
- 0.2-SNAPSHOT
- jar
- example-common
-
-
- 1.7
- 1.7
- 0.2-SNAPSHOT
- 2.0
- 4.11
-
-
-
-
- com.example
- example-dummy
- ${restx.version}
-
-
- com.google.guava
- guava
- 14.0-rc2
-
-
- joda-time
- joda-time
- ${joda-time.version}
-
-
- com.github.spullara.mustache.java
- compiler
- 0.8.10
-
-
- junit
- junit
- ${junit.version}
- test
-
-
- org.easytesting
- fest-assert-core
- 2.0M8
- test
-
-
-
\ No newline at end of file
diff --git a/restx-build/src/test/resources/restx/build/Module5.properties.json b/restx-build/src/test/resources/restx/build/Module5.properties.json
deleted file mode 100644
index 3342df650..000000000
--- a/restx-build/src/test/resources/restx/build/Module5.properties.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "java.version": "1.7",
- "restx.version": "0.2-SNAPSHOT",
- "guava.version": "1.0",
- "joda-time.version": "2.0",
- "junit.version": "4.11"
-}
diff --git a/restx-build/src/test/resources/restx/build/Module5.restx.json b/restx-build/src/test/resources/restx/build/Module5.restx.json
deleted file mode 100644
index aa990aa76..000000000
--- a/restx-build/src/test/resources/restx/build/Module5.restx.json
+++ /dev/null
@@ -1,21 +0,0 @@
-{
- "parent": "com.example:example-parent:0.8",
- "module": "com.example:example-common:${restx.version}",
-
- "properties": {
- "@files": ["Module5.properties.json"]
- },
-
- "dependencies": {
- "compile": [
- "com.example:example-dummy:${restx.version}",
- "com.google.guava:guava:14.0-rc2",
- "joda-time:joda-time:${joda-time.version}",
- "com.github.spullara.mustache.java:compiler:0.8.10"
- ],
- "test": [
- "junit:junit:${junit.version}",
- "org.easytesting:fest-assert-core:2.0M8"
- ]
- }
-}
\ No newline at end of file
diff --git a/restx-build/src/test/resources/restx/build/Module6.pom.xml b/restx-build/src/test/resources/restx/build/Module6.pom.xml
deleted file mode 100644
index 252a5822c..000000000
--- a/restx-build/src/test/resources/restx/build/Module6.pom.xml
+++ /dev/null
@@ -1,62 +0,0 @@
-
-
- 4.0.0
-
-
- com.example
- example-parent
- 0.8
-
-
- com.example
- example-common
- 0.2-SNAPSHOT
- jar
- example-common
-
-
- 1.7
- 1.7
- 0.2-SNAPSHOT
- 2.0
- 4.11
-
-
-
-
- com.example
- example-dummy
- ${restx.version}
- zip
-
-
- com.google.guava
- guava
- 14.0-rc2
-
-
- joda-time
- joda-time
- ${joda-time.version}
-
-
- com.github.spullara.mustache.java
- compiler
- 0.8.10
-
-
- junit
- junit
- ${junit.version}
- test
-
-
- org.easytesting
- fest-assert-core
- 2.0M8
- test
-
-
-
\ No newline at end of file
diff --git a/restx-build/src/test/resources/restx/build/Module6.restx.json b/restx-build/src/test/resources/restx/build/Module6.restx.json
deleted file mode 100644
index 0a0df101d..000000000
--- a/restx-build/src/test/resources/restx/build/Module6.restx.json
+++ /dev/null
@@ -1,21 +0,0 @@
-{
- "parent": "com.example:example-parent:0.8",
- "module": "com.example:example-common:${restx.version}",
-
- "properties": {
- "@files": ["Module5.properties.json"]
- },
-
- "dependencies": {
- "compile": [
- "com.example:example-dummy:${restx.version}:zip",
- "com.google.guava:guava:14.0-rc2",
- "joda-time:joda-time:${joda-time.version}",
- "com.github.spullara.mustache.java:compiler:0.8.10"
- ],
- "test": [
- "junit:junit:${junit.version}",
- "org.easytesting:fest-assert-core:2.0M8"
- ]
- }
-}
\ No newline at end of file
diff --git a/restx-build/src/test/resources/restx/build/Module7.pom.xml b/restx-build/src/test/resources/restx/build/Module7.pom.xml
deleted file mode 100644
index 9b6b292c2..000000000
--- a/restx-build/src/test/resources/restx/build/Module7.pom.xml
+++ /dev/null
@@ -1,82 +0,0 @@
-
-
- 4.0.0
-
-
- com.example
- example-parent
- 0.8
-
-
- com.example
- example-common
- 0.2-SNAPSHOT
- jar
- example-common
-
-
- 1.7
- 1.7
- 2.0
- 4.11
-
-
-
-
- com.google.guava
- guava
- 14.0-rc2
-
-
- joda-time
- joda-time
- ${joda-time.version}
-
-
- com.github.spullara.mustache.java
- compiler
- 0.8.10
-
-
- junit
- junit
- ${junit.version}
- test
-
-
-
-
-
- maven-dependency-plugin
-
-
- copy-dependencies
- install
-
- copy-dependencies
-
-
- compile
- runtime
- test
-
-
-
-
-
- org.apache.maven.plugins
- maven-war-plugin
-
-
-
-
- ${project.war.resources.directory}
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/restx-build/src/test/resources/restx/build/Module7.restx.json b/restx-build/src/test/resources/restx/build/Module7.restx.json
deleted file mode 100644
index bc2065340..000000000
--- a/restx-build/src/test/resources/restx/build/Module7.restx.json
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "parent": "com.example:example-parent:0.8",
- "module": "com.example:example-common:0.2-SNAPSHOT",
-
- "properties": {
- "java.version": "1.7",
- "joda-time.version": "2.0",
- "junit.version": "4.11"
- },
-
- "fragments": {
- "maven": [
- "classpath:///restx/build/fragments/maven/copy-dependencies.xml",
- "classpath:///restx/build/fragments/maven/custom-war-resources.xml"
- ]
- },
-
- "dependencies": {
- "compile": [
- "com.google.guava:guava:14.0-rc2",
- "joda-time:joda-time:${joda-time.version}",
- "com.github.spullara.mustache.java:compiler:0.8.10"
- ],
- "test": [
- "junit:junit:${junit.version}"
- ]
- }
-}
\ No newline at end of file
diff --git a/restx-build/src/test/resources/restx/build/Module8.pom.xml b/restx-build/src/test/resources/restx/build/Module8.pom.xml
deleted file mode 100644
index 314becc89..000000000
--- a/restx-build/src/test/resources/restx/build/Module8.pom.xml
+++ /dev/null
@@ -1,62 +0,0 @@
-
-
- 4.0.0
-
-
- com.example
- example-parent
- 0.8
-
-
- com.example
- example-common
- 0.2-SNAPSHOT
- jar
- example-common
-
-
- 1.7
- 1.7
- 2.0
- 4.11
-
-
-
-
- com.sun.tools
- tools
- ${java.version}
- system
- ${java.home}/../lib/tools.jar
-
-
- com.google.guava
- guava
- 14.0-rc2
-
-
- joda-time
- joda-time
- ${joda-time.version}
-
-
- com.github.spullara.mustache.java
- compiler
- 0.8.10
-
-
- junit
- junit
- ${junit.version}
- test
-
-
- org.easytesting
- fest-assert-core
- 2.0M8
- test
-
-
-
\ No newline at end of file
diff --git a/restx-build/src/test/resources/restx/build/Module8.restx.json b/restx-build/src/test/resources/restx/build/Module8.restx.json
deleted file mode 100644
index fd10489c0..000000000
--- a/restx-build/src/test/resources/restx/build/Module8.restx.json
+++ /dev/null
@@ -1,25 +0,0 @@
-{
- "parent": "com.example:example-parent:0.8",
- "module": "com.example:example-common:0.2-SNAPSHOT",
-
- "properties": {
- "java.version": "1.7",
- "joda-time.version": "2.0",
- "junit.version": "4.11"
- },
-
- "dependencies": {
- "system": [
- "com.sun.tools:tools:${java.version}"
- ],
- "compile": [
- "com.google.guava:guava:14.0-rc2",
- "joda-time:joda-time:${joda-time.version}",
- "com.github.spullara.mustache.java:compiler:0.8.10"
- ],
- "test": [
- "junit:junit:${junit.version}",
- "org.easytesting:fest-assert-core:2.0M8"
- ]
- }
-}
\ No newline at end of file
diff --git a/restx-build/src/test/resources/restx/build/Module9.pom.xml b/restx-build/src/test/resources/restx/build/Module9.pom.xml
deleted file mode 100644
index ec4436a90..000000000
--- a/restx-build/src/test/resources/restx/build/Module9.pom.xml
+++ /dev/null
@@ -1,56 +0,0 @@
-
-
- 4.0.0
-
-
- com.example
- example-parent
- 0.8
-
-
- com.example
- example-common
- 0.2-SNAPSHOT
- jar
- example-common
-
-
- 1.7
- 1.7
- 2.0
- 4.11
-
-
-
-
- com.google.guava
- guava
- 14.0-rc2
-
-
- joda-time
- joda-time
- ${joda-time.version}
-
-
- com.github.spullara.mustache.java
- compiler
- 0.8.10
- true
-
-
- junit
- junit
- ${junit.version}
- test
-
-
- org.easytesting
- fest-assert-core
- 2.0M8
- test
-
-
-
\ No newline at end of file
diff --git a/restx-build/src/test/resources/restx/build/Module9.restx.json b/restx-build/src/test/resources/restx/build/Module9.restx.json
deleted file mode 100644
index 8480b8b4a..000000000
--- a/restx-build/src/test/resources/restx/build/Module9.restx.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "parent": "com.example:example-parent:0.8",
- "module": "com.example:example-common:0.2-SNAPSHOT",
-
- "properties": {
- "java.version": "1.7",
- "joda-time.version": "2.0",
- "junit.version": "4.11"
- },
-
- "dependencies": {
- "compile": [
- "com.google.guava:guava:14.0-rc2",
- "joda-time:joda-time:${joda-time.version}",
- "com.github.spullara.mustache.java:compiler:0.8.10!optional"
- ],
- "test": [
- "junit:junit:${junit.version}",
- "org.easytesting:fest-assert-core:2.0M8"
- ]
- }
-}
\ No newline at end of file
diff --git a/restx-core-shell/md.restx.json b/restx-core-shell/md.restx.json
deleted file mode 100644
index 877f5f78f..000000000
--- a/restx-core-shell/md.restx.json
+++ /dev/null
@@ -1,25 +0,0 @@
-{
- "parent": "io.restx:restx-parent:${restx.version}",
- "module": "io.restx:restx-core-shell:${restx.version}",
-
- "properties": {
- "@files": ["../restx.build.properties.json"]
- },
-
- "dependencies": {
- "compile": [
- "io.restx:restx-factory:${restx.version}",
- "io.restx:restx-core:${restx.version}",
- "io.restx:restx-shell:${restx.version}",
- "io.restx:restx-shell-manager:${restx.version}",
- "io.restx:restx-build:${restx.version}",
- "org.apache.ivy:ivy:${ivy.version}",
- "org.mindrot:jbcrypt:0.3m"
- ],
- "test": [
- "junit:junit:${junit.version}",
- "org.apache.maven.shared:maven-verifier:${maven-verifier.version}",
- "org.mockito:mockito-all:${mockito.version}"
- ]
- }
-}
diff --git a/restx-core-shell/module.ivy b/restx-core-shell/module.ivy
deleted file mode 100644
index 51f294e5b..000000000
--- a/restx-core-shell/module.ivy
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/restx-core-shell/pom.xml b/restx-core-shell/pom.xml
deleted file mode 100644
index b990ccc53..000000000
--- a/restx-core-shell/pom.xml
+++ /dev/null
@@ -1,61 +0,0 @@
-
-
- 4.0.0
-
-
- io.restx
- restx-parent
- 0.35-SNAPSHOT
-
-
- restx-core-shell
- restx-core-shell
-
-
-
- io.restx
- restx-factory
-
-
- io.restx
- restx-core
-
-
- io.restx
- restx-shell
-
-
- io.restx
- restx-shell-manager
-
-
- io.restx
- restx-build
-
-
- org.apache.ivy
- ivy
-
-
- org.mindrot
- jbcrypt
-
-
- junit
- junit
- test
-
-
- org.apache.maven.shared
- maven-verifier
- test
-
-
- org.mockito
- mockito-all
- test
-
-
-
diff --git a/restx-core-shell/src/main/java/restx/core/shell/AppShellCommand.java b/restx-core-shell/src/main/java/restx/core/shell/AppShellCommand.java
deleted file mode 100644
index a13e5da42..000000000
--- a/restx-core-shell/src/main/java/restx/core/shell/AppShellCommand.java
+++ /dev/null
@@ -1,902 +0,0 @@
-package restx.core.shell;
-
-import com.google.common.base.*;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
-import com.google.common.io.ByteStreams;
-import com.google.common.io.Files;
-import jline.console.completer.ArgumentCompleter;
-import jline.console.completer.Completer;
-import jline.console.completer.StringsCompleter;
-import restx.AppSettings;
-import restx.Apps;
-import restx.RestxContext;
-import restx.build.ModuleDescriptor;
-import restx.build.RestxBuild;
-import restx.build.RestxJsonSupport;
-import restx.common.Archetype;
-import restx.common.UUIDGenerator;
-import restx.common.Version;
-import restx.factory.Component;
-import restx.factory.NamedComponent;
-import restx.factory.SingletonFactoryMachine;
-import restx.plugins.ModulesManager;
-import restx.shell.RestxShell;
-import restx.shell.ShellCommandRunner;
-import restx.shell.ShellIvy;
-import restx.shell.StdShellCommand;
-
-import java.io.*;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
-import java.util.Random;
-
-import static java.nio.file.Files.newOutputStream;
-import static restx.common.MoreFiles.extractZip;
-import static restx.common.MorePreconditions.checkPresent;
-
-/**
- * User: xavierhanin
- * Date: 4/10/13
- * Time: 8:53 PM
- */
-@Component
-public class AppShellCommand extends StdShellCommand {
- private final UUIDGenerator uuidGenerator;
-
- public AppShellCommand(UUIDGenerator uuidGenerator) {
- super(ImmutableList.of("app"), "app related commands: creates a new app, run your app, ...");
- this.uuidGenerator = uuidGenerator;
- }
-
- @Override
- protected Optional extends ShellCommandRunner> doMatch(String line) {
- List args = splitArgs(line);
-
- if (args.size() < 2) {
- return Optional.absent();
- }
-
- switch (args.get(1)) {
- case "new":
- return Optional.of(new NewAppCommandRunner());
- case "compile":
- return Optional.of(new CompileAppCommandRunner(args));
- case "generate-start-script":
- return Optional.of(new GenerateStartCommandRunner(args));
- case "run":
- return Optional.of(new RunAppCommandRunner(args));
- case "grab":
- return Optional.of(new GrabAppCommandRunner(args));
- case "archive":
- return Optional.of(new ArchiveAppCommandRunner(args));
- }
-
- return Optional.absent();
- }
-
- public static Path standardCachedAppPath(String appname) {
- return Paths.get(System.getProperty("restx.shell.home"), "apps/"+appname);
- }
-
- @Override
- public void man(Appendable appendable) throws IOException {
- super.man(appendable);
- }
-
- protected String resourceMan() {
- return "restx/core/shell/app.man";
- }
-
- @Override
- public Iterable getCompleters() {
- return ImmutableList.of(new ArgumentCompleter(
- new StringsCompleter("app"), new StringsCompleter("new", "run", "compile", "generate-start-script")));
- }
-
- static class NewAppDescriptor {
- String appName;
- String targetPath;
- String groupId;
- String artifactId;
- String mainPackage;
- String version;
- List buildFiles;
- String signatureKey;
- String adminPassword;
- String defaultPort;
- String baseAPIPath;
- String javaVersion;
- String restxVersion;
- boolean generateHelloResource;
- boolean includeStatsModule;
- boolean useSrvuiLayout;
- String boostrapUIOption;
- String boostrapUITemplate;
- }
-
- class NewAppCommandRunner implements ShellCommandRunner {
-
- private Archetype srvMainTemplates = Archetype.buildArchetype("templates.srv.main");
- private Archetype srvHelloResourceTemplates = Archetype.buildArchetype("templates.srv.helloResource");
- private Archetype rootMainTemplates = Archetype.buildArchetype("templates.root.main");
- private Archetype rootNoNodeTemplates = Archetype.buildArchetype("templates.root.no-node");
- private Archetype rootGruntBowerTemplates = Archetype.buildArchetype("templates.root.grunt-bower");
-
- private final ImmutableMap uiTemplatesPackageLocations = ImmutableMap.of(
- "html5", "https://github.com/restx/html5/archive/restx.zip",
- "angular-bootstrap", "https://github.com/restx/angular-bootstrap/archive/restx.zip",
- "angular-bootstrap-grunt-bower", "https://github.com/restx/angular-bootstrap-grunt-bower/archive/restx.zip"
- );
-
- @Override
- public void run(RestxShell shell) throws Exception {
- shell.printIn("Welcome to RESTX APP bootstrap!", RestxShell.AnsiCodes.ANSI_GREEN);
- shell.println("");
- shell.println("This command will ask you a few questions to generate your brand new RESTX app.");
- shell.println("For any question you can get help by answering '??' (without the quotes).");
- shell.println("");
-
- NewAppDescriptor descriptor = new NewAppDescriptor();
- descriptor.appName = "";
- while (Strings.isNullOrEmpty(descriptor.appName)) {
- descriptor.appName = shell.ask("App name? ", "",
- "This is the name of the application you are creating.\n" +
- "It can contain spaces, it's used mainly for documentation and to provide default for other values.\n" +
- "Examples: Todo, Foo Bar, ...");
- }
-
- descriptor.targetPath = shell.ask("target directory [%s]? ",
- descriptor.appName.replaceAll("\\s+", "-").toLowerCase(Locale.ENGLISH),
- "This is the location where the app will be generated.\n" +
- "You can use . if you want to generate in current directory.\n" +
- "Note that restx will create the directory if it doesn't exist.");
- descriptor.groupId = shell.ask("group id [%s]? ",
- descriptor.appName.replaceAll("\\s+", "-").toLowerCase(Locale.ENGLISH),
- "This is the identifier of the group or organization producing the application.\n" +
- "In the Maven world this is called a groupId, in Ivy it's called organization.\n" +
- "It MUST NOT contain spaces nor columns (':'), and is usually a reversed domain name.\n" +
- "Examples: io.restx, com.example, ...");
- descriptor.artifactId = shell.ask("artifact id [%s]? ",
- descriptor.appName.replaceAll("\\s+", "-").toLowerCase(Locale.ENGLISH),
- "This is the identifier of the app module.\n" +
- "In the Maven world this is called an artifactId, in Ivy it's called module.\n" +
- "It MUST NOT contain spaces nor columns (':'), and is usually a dash separated lower case word.\n" +
- "Examples: myapp, todo, foo-app, ...")
- .replaceAll("\\s+", "-");
- descriptor.mainPackage = shell.ask("main package [%s]? ",
- descriptor.groupId.replaceAll("\\-", ".").toLowerCase(Locale.ENGLISH),
- "This is the main package in which you will develop your application.\n" +
- "In Java convention it should start with a reversed domain name followed by the app name\n" +
- "but for applications (as opposed to APIs) we prefer to use a short name, like that app name.\n" +
- "It MUST follow Java package names restrictions, so MUST NOT contain spaces\n" +
- "Examples: myapp, com.example.todoapp, ...");
- descriptor.version = shell.ask("version [%s]? ", "0.1-SNAPSHOT",
- "This is the name of the first version of the app you are targetting.\n" +
- "It's recommended to use Maven convention to suffix it with -SNAPSHOT if you plan to use Maven for your app\n" +
- "Examples: 0.1-SNAPSHOT, 1.0, ...");
-
- while (descriptor.buildFiles == null) {
- String option = shell.ask("Select module descriptor(s) you want to generate :\n" +
- " [ 1] md.restx.json only.\n" +
- " [ 2] module.ivy only.\n" +
- " [ 3] pom.xml only.\n" +
- " [ 4] md.restx.json + module.ivy.\n" +
- " [ 5] md.restx.json + pom.xml.\n" +
- " [ all] md.restx.json + pom.xml + module.ivy.\n" +
- " [none] no module descriptor. WARNING: this will make it harder to build your app.\n" +
- "\n" +
- " Which option [%s]? ",
- "all",
- "This allows to generate module descriptor(s) for your app.\n" +
- "Module descriptor types:\n" +
- "\t- 'md.restx.json': get a RestX module descriptor generated for you.\n" +
- "\t- 'module.ivy': get an Easyant compatible Ivy file generated for you.\n" +
- "\t- 'pom.xml': get a Maven POM generated for you.\n" +
- "If you don't know these tools, use default answer.\n");
- switch (option.trim()) {
- case "1": descriptor.buildFiles = Arrays.asList(ModuleDescriptorType.RESTX); break;
- case "2": descriptor.buildFiles = Arrays.asList(ModuleDescriptorType.IVY); break;
- case "3": descriptor.buildFiles = Arrays.asList(ModuleDescriptorType.MAVEN); break;
- case "4": descriptor.buildFiles = Arrays.asList(ModuleDescriptorType.RESTX, ModuleDescriptorType.IVY); break;
- case "5": descriptor.buildFiles = Arrays.asList(ModuleDescriptorType.RESTX, ModuleDescriptorType.MAVEN); break;
- case "all": descriptor.buildFiles = Arrays.asList(ModuleDescriptorType.values()); break;
- case "none": descriptor.buildFiles = Collections.emptyList(); break;
- default: descriptor.buildFiles = null;
- }
- }
-
- descriptor.javaVersion = shell.ask("java version [%s]? ",
- System.getProperty("java.version").replaceAll("^(\\d+\\.\\d+).*$", "$1"),
- "The version of Java you want to use in your application.\n" +
- "RESTX supports Java 7 (1.7) and Java 8 (1.8)\n" +
- "Example: 1.7, 1.8");
-
- descriptor.restxVersion = shell.ask("restx version [%s]? ", Version.getVersion("io.restx", "restx-core"));
-
- List list = Lists.newArrayList(uuidGenerator.doGenerate(),
- String.valueOf(new Random().nextLong()), descriptor.appName, descriptor.artifactId);
- Collections.shuffle(list);
- descriptor.signatureKey = shell.ask("signature key (to sign cookies) [%s]? ",
- Joiner.on(" ").join(list),
- "This is used as salt for signing stuff exchanged with the client.\n" +
- "Use something fancy or keep what is proposed by default, but make sure to not share that publicly.");
-
- descriptor.adminPassword = shell.ask("admin password (to authenticate on restx console) [%s]? ",
- String.valueOf(new Random().nextInt(10000)),
- "This is used as password for the admin user to authenticate on restx console.\n" +
- "This is only a default way to authenticate out of the box, restx security is very flexible.");
-
- descriptor.defaultPort = shell.ask("default port [%s]? ", "8080",
- "This is the default port used when using embedded version.\n" +
- "Usually Java web containers use 8080, it may be a good idea to use a different port to avoid \n" +
- "conflicts with another servlet container.\n" +
- "You can also use port 80 if you want to serve your API directly with the embedded server\n" +
- "and no reverse proxy in front of it. But beware that you may need admin privileges for that.\n" +
- "Examples: 8080, 8086, 8000, 80");
- descriptor.baseAPIPath = shell.ask("base API path [%s]? ", "/api",
- "This is the base API path on which RESTX will handle requests.\n" +
- "Being focused on REST API only, RESTX is usually shared with either static or dynamic \n" +
- "resources serving (HTML, CSS, JS, images, ...) and therefore is used to handle requests on\n" +
- "only a sub path of the web app.\n" +
- "If you plan to use it to serve requests from an API only domain (eg api.example.com)\n" +
- "you can use '' (empty string) for this path.\n" +
- "Examples: /api, /api/v2, /restx, ...");
-
- descriptor.generateHelloResource = shell.askBoolean("generate hello resource example [Y/n]? ", "y",
- "This will generate an example resource with an associated spec test so that your boostrapped\n" +
- "application can be used as soon as it has been generated.\n" +
- "If this is the first app you generate with RESTX, it's probably a good idea to generate\n" +
- "this example resource.\n" +
- "If you already know RESTX by heart you shouldn't be reading this message anyway :)");
-
- descriptor.includeStatsModule = shell.askBoolean("include stats module and share anonymous stats on your app [Y/n]? ", "y",
- "This will include the restx-stats-admin module which collects anonymous stats on your app\n" +
- "and share them with the community.\n" +
- "See http://restx.io/stats.html for more details.");
-
- descriptor.useSrvuiLayout = shell.askBoolean("do you want to use srv/ui layout [y/N]?", "n",
- "This will organize your app in 2 modules:\n" +
- " - `srv`: for the server part, using RESTX to serve the REST API.\n" +
- " - `ui`: for the front part, using your front end framework of choice (Angular, Ember, ...)\n" +
- "If you prefer a different code organization between your front end and back end,\n" +
- "like putting your front end resources in `src/main/webapp` as is usual for Java Web Development,\n" +
- "don't use this option and organize your frontent as you like.");
-
- if (descriptor.useSrvuiLayout) {
- descriptor.boostrapUIOption = shell.ask("How do you want to bootstrap your UI (yo/restx/none) [restx]?", "restx",
- "Select how to boostrap your UI:\n" +
- " - `yo`: use yeoman (you need to have yeoman installed).\n" +
- " - `restx`: RESTX has basic UI generation support.\n" +
- " select this option if you don't have yeoman installed but still want to have\n" +
- " basic UI boostrapped.\n" +
- " - `none`: don't bootstrap the UI, leave it empty." +
- " you can use this option if you want to bootstrap it yourself.\n");
- if ("yo".equalsIgnoreCase(descriptor.boostrapUIOption)) {
- while (Strings.isNullOrEmpty(descriptor.boostrapUITemplate)) {
- descriptor.boostrapUITemplate = shell.ask("Which generator do you want to use?:",
- "",
- "Select the yeoman generator you want to use.\n" +
- "Check http://yeoman.io/community-generators.html to get the list of generators.\n" +
- "Examples: angular, ember, mobile, ...");
- }
- } else if ("restx".equalsIgnoreCase(descriptor.boostrapUIOption)) {
- while (descriptor.boostrapUITemplate == null) {
- String option = shell.ask("Select the template you want to use:\n" +
- " [ 1] HTML5 Boilerplate\n" +
- " Use this if you want a very basic HTML5 bootstrap, with no additional tool required.\n" +
- " [ 2] Angular, Twitter Bootstrap\n" +
- " Use this if you want a more convenient bootstrap, with no additional tool required.\n" +
- " [ 3] Angular, Twitter Bootstrap. Use grunt for building and bower to manage dependencies.\n" +
- " Use this if you want a convenient bootstrap using the very popular frontend tools.\n" +
- " You will need:\n" +
- " - nodejs: http://nodejs.org/download/\n" +
- " - grunt: http://gruntjs.com/getting-started\n" +
- " - bower: http://bower.io/\n" +
- "\n" +
- " Which template do you want [1]? ",
- "1",
- "Select the template to use depending on your preferences and tools installed.\n" +
- "If you want more choices, you can either contribute to RESTX or use yeoman");
- switch (option.trim()) {
- case "1": descriptor.boostrapUITemplate = "html5"; break;
- case "2": descriptor.boostrapUITemplate = "angular-bootstrap"; break;
- case "3": descriptor.boostrapUITemplate = "angular-bootstrap-grunt-bower"; break;
- default: descriptor.boostrapUITemplate = null;
- }
- }
- }
- }
-
- Path appPath = generateApp(descriptor, shell);
-
- shell.cd(appPath);
-
- if (shell.askBoolean("Do you want to install its deps and run it now? [y/N]", "n",
- "By answering yes restx will resolve and install the dependencies of the app and run it.\n" +
- "You can always install the deps later by using the `deps install` command\n" +
- "and run the app with the `app run` command")) {
- shell.println("restx> deps install");
- new DepsShellCommand.InstallDepsCommandRunner().run(shell);
- shell.println("restx> app run");
- new RunAppCommandRunner(Collections.emptyList()).run(shell);
- }
- }
-
- public Path generateApp(NewAppDescriptor descriptor, RestxShell shell) throws IOException {
-
- ImmutableMap scope = ImmutableMap.builder()
- .put("appName", descriptor.appName)
- .put("groupId", descriptor.groupId)
- .put("artifactId", descriptor.artifactId)
- .put("mainPackage", descriptor.mainPackage)
- .put("packagePath", descriptor.mainPackage.replace('.', '/'))
- .put("version", descriptor.version)
- .put("signatureKey", descriptor.signatureKey)
- .put("adminPassword", descriptor.adminPassword)
- .put("defaultPort", descriptor.defaultPort)
- .put("baseAPIPath", descriptor.baseAPIPath)
- .put("javaVersion", descriptor.javaVersion)
- .put("restxVersion", descriptor.restxVersion)
- .put("includeStatsModule", descriptor.includeStatsModule)
- .put("useSrvuiLayout", descriptor.useSrvuiLayout)
- .build();
-
- Path appPath = shell.currentLocation().resolve(descriptor.targetPath);
- shell.println("scaffolding app to `" + appPath.toAbsolutePath() + "` ...");
-
-
- boolean useGruntBower = false;
- Path srvModulePath;
- if (descriptor.useSrvuiLayout) {
- Path uiModulePath = appPath.resolve("ui");
- rootMainTemplates.generate(appPath, scope);
-
- if ("yo".equalsIgnoreCase(descriptor.boostrapUIOption)) {
- shell.println("you can scaffold ui with yeoman in `" + uiModulePath
- + "` using `yo " + descriptor.boostrapUITemplate + "`");
- // calling yo directly would be better, but yo is interactive, so we need to use INHERIT redirect
- // input which closes stdin at the end of the process :(
-
- useGruntBower = true; // assume users with yo will use grunt and bower
- } else if ("restx".equalsIgnoreCase(descriptor.boostrapUIOption)) {
- shell.println("scaffolding ui with restx in `" + uiModulePath + "` ...");
-
- Path uitplsPath = shell.installLocation().resolve("plugins/templates/ui");
- File tplDir = uitplsPath.resolve(descriptor.boostrapUITemplate).toFile();
- if (!tplDir.exists()) {
- URL tplZipURL = new URL(uiTemplatesPackageLocations.get(descriptor.boostrapUITemplate));
- uitplsPath.toFile().mkdirs();
- shell.println("downloading UI template");
- File zipFile = uitplsPath.resolve(descriptor.boostrapUITemplate + ".zip").toFile();
- shell.download(tplZipURL, zipFile);
-
- extractZip(zipFile, tplDir);
- if (tplDir.list().length == 1 && tplDir.listFiles()[0].isDirectory()) {
- // zip has a single root directory, we remove it
- File dir = tplDir.listFiles()[0];
- File[] files = dir.listFiles();
- for (int i = 0; i < files.length; i++) {
- File file = files[i];
- Files.move(file, new File(tplDir, file.getName()));
- }
- dir.delete();
- }
- }
-
- Archetype.buildArchetype(tplDir.toPath()).generate(uiModulePath, scope);
- useGruntBower = uiModulePath.resolve("bower.json").toFile().exists();
- }
-
- if (useGruntBower) {
- rootGruntBowerTemplates.generate(appPath, scope);
- } else {
- rootNoNodeTemplates.generate(appPath, scope);
- }
-
- srvModulePath = appPath.resolve("srv");
- shell.println("scaffolding srv with restx in `" + srvModulePath + "` ...");
- } else {
- srvModulePath = appPath;
- }
-
- srvMainTemplates.generate(srvModulePath, scope);
- if (descriptor.buildFiles.contains(ModuleDescriptorType.IVY)) {
- shell.println("generating module.ivy ...");
- RestxBuild.convert(srvModulePath.toAbsolutePath() + "/md.restx.json", srvModulePath.toAbsolutePath() + "/module.ivy");
- }
- if (descriptor.buildFiles.contains(ModuleDescriptorType.MAVEN)) {
- shell.println("generating pom.xml ...");
- RestxBuild.convert(srvModulePath.toAbsolutePath() + "/md.restx.json", srvModulePath.toAbsolutePath() + "/pom.xml");
- }
- // We remove md.restx.json file *after* having generated pom and/or ivy file as it is needed for their generation
- if (!descriptor.buildFiles.contains(ModuleDescriptorType.RESTX)) {
- shell.println("removing md.restx.json ...");
- srvModulePath.resolve(ModuleDescriptorType.RESTX.getDescriptorFileName()).toFile().delete();
- }
-
- if (descriptor.generateHelloResource) {
- shell.println("generating hello resource ...");
- srvHelloResourceTemplates.generate(srvModulePath, scope);
- }
-
- shell.printIn("Congratulations! - Your app is now ready in " + appPath.toAbsolutePath(), RestxShell.AnsiCodes.ANSI_GREEN);
- shell.println("");
- shell.println("");
-
- if (descriptor.useSrvuiLayout) {
- shell.println("Your app has 2 modules: ui and srv\n" +
- "In srv, you can:\n" +
- " - open the module in your IDE by importing the Maven pom, and run the \n" +
- " `" + descriptor.mainPackage + ".AppServer` class to launch\n" +
- " - run it from restx shell, using:\n" +
- " deps install\n" +
- " to install its dependencies\n" +
- " app run\n" +
- " to run it\n");
- if (useGruntBower) {
- shell.println(
- "In ui you can:\n" +
- " - open and edit your front end source files with your favorite editor\n" +
- " - install local grunt with\n" +
- " npm install\n" +
- " - install app frontend dependencies listed in bower.json with\n" +
- " bower install\n" +
- " - run development server with:\n" +
- " grunt server\n"
- );
- } else {
- shell.println(
- "In ui you can:\n" +
- " - open and edit your front end source files with your favorite editor\n" +
- " - copy files to `dist` directory to make them available to RESTX web server\n" +
- " hint: you can use the build.sh for that\n");
- }
- shell.println(
- "At root level you can:\n" +
- " - build a production ready war using Maven (Linux/MacOS only):\n" +
- " mvn package");
- } else {
- shell.println("You can now:\n" +
- " - open the app in your IDE by importing the Maven pom, and run the \n" +
- " `" + descriptor.mainPackage + ".AppServer` class to launch\n" +
- " - run it from restx shell, using:\n" +
- " deps install\n" +
- " to install its dependencies\n" +
- " app run\n" +
- " to run it\n" +
- " - build a war using the selected build tool, eg\n" +
- " mvn package");
- }
-
- shell.printIn("Enjoy!", RestxShell.AnsiCodes.ANSI_GREEN);
- shell.println("");
-
- return srvModulePath;
- }
- }
-
- private class CompileAppCommandRunner implements ShellCommandRunner {
- private ShellAppRunner.CompileMode compileMode = ShellAppRunner.CompileMode.ALL;
-
- public CompileAppCommandRunner(List args) {
- }
-
- @Override
- public void run(RestxShell shell) throws Exception {
- AppSettings appSettings = shell.getFactory()
- .getComponent(AppSettings.class);
- compileMode.compile(
- shell,
- Paths.get(appSettings.targetClasses()),
- Paths.get(appSettings.targetDependency()),
- Paths.get(appSettings.mainSources()),
- Paths.get(appSettings.mainResources()),
- null);
- }
- }
-
- private class GenerateStartCommandRunner implements ShellCommandRunner {
- private String appClassName;
-
- public GenerateStartCommandRunner(List args) {
- if (args.size() > 2) {
- appClassName = args.get(2);
- }
- }
-
- @Override
- public void run(RestxShell shell) throws Exception {
- AppSettings appSettings = shell.getFactory()
- .getComponent(AppSettings.class);
- Optional pack = Optional.absent();
- if (appClassName == null) {
- pack = Apps.with(appSettings)
- .guessAppBasePackage(shell.currentLocation());
- if (!pack.isPresent()) {
- shell.printIn("can't find base app package, src/main/java should contain a AppServer.java source file somewhere",
- RestxShell.AnsiCodes.ANSI_RED);
- shell.println("");
- shell.println("alternatively you can provide the class to run with `app generate-start-script `");
- return;
- }
- appClassName = pack.get() + ".AppServer";
- } else {
- pack = Optional.of(appClassName.substring(0, appClassName.lastIndexOf('.')));
- }
-
-
- File startSh = shell.currentLocation().resolve("start.sh").toFile();
- Files.write(
- "#!/bin/sh\n\n" +
- getCommand(appSettings, pack, ":") + " $VM_OPTIONS " +
- " " + appClassName + "\n",
- startSh, Charsets.UTF_8);
- startSh.setExecutable(true);
-
- File startBat = shell.currentLocation().resolve("start.bat").toFile();
- Files.write(
- getCommand(appSettings, pack, ";") + " %VM_OPTIONS% " +
- " " + appClassName + "\r\n",
- startBat, Charsets.ISO_8859_1);
-
- shell.printIn("generated start scripts:\n" +
- "\t" + startSh.getAbsolutePath() + "\n" +
- "\t" + startBat.getAbsolutePath() + "\n",
- RestxShell.AnsiCodes.ANSI_GREEN);
- }
-
- protected String getCommand(AppSettings appSettings, Optional pack, String pathSeparator) {
- return "java" +
- " -cp \"" + appSettings.targetClasses() + pathSeparator + appSettings.targetDependency() + "/*\"" +
- " -Drestx.app.package=" + pack.get() +
- " -Drestx.mode=prod";
- }
- }
-
- private class RunAppCommandRunner implements ShellCommandRunner {
- private Optional appClassNameArg;
- private Optional appNameArg;
- private boolean quiet;
- private boolean daemon;
- private Optional restxMode;
- private List vmOptions = new ArrayList<>();
-
- public RunAppCommandRunner(List args) {
- args = new ArrayList<>(args);
- quiet = false;
- daemon = true;
- appClassNameArg = Optional.absent();
- appNameArg = Optional.absent();
- restxMode = Optional.absent();
-
- while (args.size() > 2) {
- String arg = args.get(2);
- if (arg.equalsIgnoreCase("--quiet")) {
- quiet = true;
- } else if (arg.startsWith("--fg")) {
- daemon = false;
- } else if (arg.startsWith("--mode=") || arg.startsWith("-Drestx.mode=")) {
- String mode = arg.startsWith("--mode=")?arg.substring("--mode=".length()):arg.substring("-Drestx.mode=".length());
- restxMode = Optional.of(mode);
- } else if (arg.startsWith("-D") || arg.startsWith("-X")) {
- vmOptions.add(arg);
- } else if (!appClassNameArg.isPresent() && !appNameArg.isPresent()) {
- // If an existing restx app folder stands for given arg, considering it as the appName
- // otherwise, arg will stand for a classname to execute
- if(java.nio.file.Files.exists(standardCachedAppPath(arg))) {
- appNameArg = Optional.of(arg);
- restxMode = Optional.of(restxMode.or(RestxContext.Modes.PROD));
- } else {
- appClassNameArg = Optional.of(arg);
- }
- } else {
- throw new IllegalArgumentException("app run argument not recognized: " + arg);
- }
- args.remove(2);
- }
- }
-
- @Override
- public void run(final RestxShell shell) throws Exception {
- Path shellInitialLocation = shell.currentLocation();
- if(appNameArg.isPresent()) {
- shell.cd(standardCachedAppPath(appNameArg.get()));
- }
-
- if(!ModuleDescriptorType.RESTX.resolveDescriptorFile(shell.currentLocation()).exists()) {
-
- Path srvDir = shell.currentLocation().resolve("srv");
- if(srvDir.toFile().exists()) {
- shell.cd(srvDir);
- if(!ModuleDescriptorType.RESTX.resolveDescriptorFile(shell.currentLocation()).exists()) {
- shell.println(String.format("Cannot find %s in both %s and %s",
- ModuleDescriptorType.RESTX.getDescriptorFileName(),
- shell.currentLocation().getParent().toAbsolutePath(),
- shell.currentLocation().toAbsolutePath()));
- shell.println("=> Cannot run application");
- return;
- }
- } else {
- shell.println(String.format("Cannot find %s in %s",
- ModuleDescriptorType.RESTX.getDescriptorFileName(),
- shell.currentLocation().toAbsolutePath()));
- shell.println("=> Cannot run application");
- return;
- }
- }
-
- boolean sourcesAvailable = Apps.with(shell.getFactory().getComponent(AppSettings.class)).sourcesAvailableIn(shell.currentLocation());
-
- String appClassName;
- ShellAppRunner.CompileMode compileMode;
- if(sourcesAvailable) {
- if(appClassNameArg.isPresent()) {
- appClassName = appClassNameArg.get();
- } else {
- Optional appClassNameGuessedFromRestxModule = guessAppClassnameFromRestxModule(shell);
- if(appClassNameGuessedFromRestxModule.isPresent()) {
- appClassName = appClassNameGuessedFromRestxModule.get();
- } else {
- appClassName = guessAppClassnameFromSources(shell);
- }
- }
-
- compileMode = (restxMode.isPresent() && RestxContext.Modes.PROD.equals(restxMode.get()))? ShellAppRunner.CompileMode.ALL: ShellAppRunner.CompileMode.MAIN_CLASS;
-
- if(appClassName == null) {
- shell.printIn("can't find base app package, src/main/java should contain a AppServer.java source file somewhere",
- RestxShell.AnsiCodes.ANSI_RED);
- shell.println("");
- shell.println("alternatively you can provide the class to run with `app run `");
- return;
- }
- } else {
- appClassName = appClassNameArg
- .or(guessAppClassnameFromRestxModule(shell))
- .orNull();
-
- // Consider we're in prod mode, without any auto compilation feature (since we don't have any source folder)
- compileMode = ShellAppRunner.CompileMode.NO;
- restxMode = Optional.of(RestxContext.Modes.PROD);
-
- if(appClassName == null){
- shell.printIn("can't find manifest.main.classname property in md.restx.json", RestxShell.AnsiCodes.ANSI_RED);
- shell.println("");
- shell.println("alternatively you can provide the class to run with `app run `");
- return;
- }
- }
-
- if (!DepsShellCommand.depsUpToDate(shell)) {
- shell.println("restx> deps install");
- new DepsShellCommand.InstallDepsCommandRunner().run(shell);
- }
-
- List vmOptions = new ArrayList<>(this.vmOptions);
- if(restxMode.isPresent()) {
- vmOptions.add("-Drestx.mode="+restxMode.get());
- }
-
- String basePack = appClassName.substring(0, appClassName.lastIndexOf('.'));
- AppSettings appSettings = shell.getFactory()
- .concat(new SingletonFactoryMachine<>(-10000, NamedComponent.of(String.class, "restx.app.package", basePack)))
- .getComponent(AppSettings.class);
- new ShellAppRunner(appSettings, appClassName, compileMode, quiet, daemon, vmOptions)
- .run(shell);
-
- // Moving back to initial location in case we either moved in cached apps or srv directory
- shell.cd(shellInitialLocation);
- }
-
- private Optional guessAppClassnameFromRestxModule(RestxShell shell) throws IOException {
-
- RestxJsonSupport restxJsonSupport = new RestxJsonSupport();
-
- Path restxJsonFile = shell.currentLocation().resolve(restxJsonSupport.getDefaultFileName());
- if(java.nio.file.Files.notExists(restxJsonFile)){
- return Optional.absent();
- }
-
- ModuleDescriptor moduleDescriptor = restxJsonSupport.parse(restxJsonFile);
- return Optional.fromNullable(moduleDescriptor.getProperties().get("manifest.main.classname"));
- }
-
- private String guessAppClassnameFromSources(RestxShell shell) {
- Optional pack = Apps.with(shell.getFactory().getComponent(AppSettings.class))
- .guessAppBasePackage(shell.currentLocation());
- if (!pack.isPresent()) {
- return null;
- }
- return pack.get() + ".AppServer";
- }
- }
-
- private static enum GrabbingStrategy {
- FROM_GIT(){
- @Override
- protected boolean accept(String coordinates) {
- return coordinates.endsWith(".git");
- }
-
- @Override
- public String extractProjectNameFrom(String coordinates) {
- return extractExtensionlessFilenameFromUrl(coordinates.split("#")[0]);
- }
-
- @Override
- public void unpackCoordinatesTo(String coordinates, Path destinationDir, String projectName, RestxShell shell) throws IOException {
- String url = coordinates;
- Optional ref = Optional.absent();
- if(url.contains("#")) {
- url = coordinates.split("#")[0];
- ref = Optional.of(coordinates.split("#")[1]);
- }
-
- try {
- shell.println("Cloning "+url+"...");
- Runtime.getRuntime().exec(new String[]{"git", "clone", url, "."}, new String[0], destinationDir.toFile()).waitFor();
-
- if(ref.isPresent()) {
- Runtime.getRuntime().exec(new String[]{"git", "checkout", ref.get()}, new String[0], destinationDir.toFile()).waitFor();
- }
- } catch(InterruptedException e) {
- throw Throwables.propagate(e);
- }
- }
- }, FROM_URL(){
- @Override
- protected boolean accept(String coordinates) {
- return coordinates.startsWith("file://")
- || coordinates.startsWith("http://")
- || coordinates.startsWith("https://");
- }
- @Override
- public String extractProjectNameFrom(String coordinates) {
- return extractExtensionlessFilenameFromUrl(coordinates);
- }
- @Override
- public void unpackCoordinatesTo(String coordinates, Path destinationDir, String projectName, RestxShell shell) throws IOException {
- handleSingleFileGrabbing(coordinates, destinationDir, projectName, shell, new SingleFileGrabber() {
- @Override
- public void grabSingleFileTo(String coordinates, Path destinationFile, RestxShell shell) throws IOException {
- try {
- URL url = new URL(coordinates);
- try (InputStream urlStream = url.openStream();
- OutputStream destFileOS = newOutputStream(destinationFile)) {
- ByteStreams.copy(urlStream, destFileOS);
- }
- } catch (MalformedURLException e) {
- throw Throwables.propagate(e);
- }
- }
- });
- }
- }, FROM_GAV(){
- @Override
- protected boolean accept(String coordinates) {
- return ModulesManager.isMrid(coordinates);
- }
- @Override
- public String extractProjectNameFrom(String coordinates) {
- return ModulesManager.toMrid(coordinates).getName();
- }
- @Override
- public void unpackCoordinatesTo(String coordinates, final Path destinationDir, String projectName, RestxShell shell) throws IOException {
- handleSingleFileGrabbing(coordinates, destinationDir, projectName, shell, new SingleFileGrabber() {
- @Override
- public void grabSingleFileTo(String coordinates, Path destinationFile, RestxShell shell) throws IOException {
- restx.plugins.ModuleDescriptor moduleDescriptor = new restx.plugins.ModuleDescriptor(coordinates, "app", "");
- ModulesManager modulesManager = new ModulesManager(null, ShellIvy.loadIvy(shell));
-
- List files = modulesManager.download(
- ImmutableList.of(moduleDescriptor),
- destinationDir.toFile(),
- new ModulesManager.DownloadOptions.Builder().transitive(false).build()
- );
- if(!files.get(0).equals(destinationFile.toFile())) {
- Files.move(files.get(0), destinationFile.toFile());
- }
- }
- });
- }
- };
-
- public static Optional fromCoordinates(String coordinates) {
- for(GrabbingStrategy grabbingStrategy : values()){
- if(grabbingStrategy.accept(coordinates)) {
- return Optional.of(grabbingStrategy);
- }
- }
- return Optional.absent();
- }
-
- private static interface SingleFileGrabber {
- void grabSingleFileTo(String coordinates, Path destinationFile, RestxShell shell) throws IOException;
- }
-
- protected void handleSingleFileGrabbing(String coordinates, Path destinationDir, String projectName, RestxShell shell, SingleFileGrabber singleFileGrabber) throws IOException {
- Path jarFile = destinationDir.resolve(projectName+".jar");
- Files.createParentDirs(jarFile.toFile());
-
- singleFileGrabber.grabSingleFileTo(coordinates, jarFile, shell);
-
- AppSettings appSettings = shell.getFactory().getComponent(AppSettings.class);
- new RestxArchive(jarFile).unpack(destinationDir, appSettings);
- jarFile.toFile().delete();
- }
-
- protected static String extractExtensionlessFilenameFromUrl(String coordinates) {
- String filename = coordinates.substring(coordinates.lastIndexOf("/")+1);
- filename = filename.contains("?")?filename.substring(0, filename.indexOf("?")):filename;
- filename = filename.contains(".")?filename.substring(0, filename.lastIndexOf(".")):filename;
- return filename;
- }
-
- protected abstract boolean accept(String coordinates);
- public abstract String extractProjectNameFrom(String coordinates);
- public abstract void unpackCoordinatesTo(String coordinates, Path destinationDir, String projectName, RestxShell shell) throws IOException;
- }
-
- private class GrabAppCommandRunner implements ShellCommandRunner {
-
- private final String projectName;
- private final String coordinates;
- private final GrabbingStrategy grabbingStrategy;
- private final Path destinationDirectoy;
-
- public GrabAppCommandRunner(List args) {
- args = new ArrayList<>(args);
-
- if(args.size() < 3) {
- throw new IllegalArgumentException("app grab : missing coordinates argument");
- }
-
- this.coordinates = args.get(2);
- this.grabbingStrategy = checkPresent(GrabbingStrategy.fromCoordinates(this.coordinates),
- "app grab : cannot found a grabbing strategy for coordinates: " + this.coordinates);
-
- this.projectName = this.grabbingStrategy.extractProjectNameFrom(this.coordinates);
- this.destinationDirectoy = args.size() >= 4 ? Paths.get(args.get(3)) : standardCachedAppPath(projectName);
- }
-
- @Override
- public void run(RestxShell shell) throws Exception {
- Files.createParentDirs(destinationDirectoy.resolve("uselessUnexistingFile").toFile());
-
- this.grabbingStrategy.unpackCoordinatesTo(this.coordinates, this.destinationDirectoy, this.projectName, shell);
-
- shell.cd(destinationDirectoy);
- }
- }
-
- private class ArchiveAppCommandRunner implements ShellCommandRunner {
- private final Path jarFile;
-
- public ArchiveAppCommandRunner(List args) {
- if(args.size() < 3) {
- throw new IllegalArgumentException("app archive : missing jarFile argument");
- }
-
- this.jarFile = Paths.get(args.get(2));
- }
-
- @Override
- public void run(RestxShell shell) throws Exception {
- AppSettings appSettings = shell.getFactory().getComponent(AppSettings.class);
- new RestxArchive(jarFile).pack(
- shell.currentLocation(),
- shell.currentLocation().resolve(appSettings.targetClasses()),
- Arrays.asList("target", "tmp", "logs")
- );
- }
- }
-}
diff --git a/restx-core-shell/src/main/java/restx/core/shell/DepsShellCommand.java b/restx-core-shell/src/main/java/restx/core/shell/DepsShellCommand.java
deleted file mode 100644
index eaeecf2bd..000000000
--- a/restx-core-shell/src/main/java/restx/core/shell/DepsShellCommand.java
+++ /dev/null
@@ -1,293 +0,0 @@
-package restx.core.shell;
-
-import com.google.common.base.*;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableList;
-import com.google.common.hash.Hashing;
-import com.google.common.io.Files;
-import jline.console.completer.ArgumentCompleter;
-import jline.console.completer.Completer;
-import jline.console.completer.StringsCompleter;
-import org.apache.ivy.Ivy;
-import org.apache.ivy.core.report.ResolveReport;
-import org.apache.ivy.core.retrieve.RetrieveOptions;
-import restx.AppSettings;
-import restx.build.*;
-import restx.build.ModuleDescriptor;
-import restx.factory.Component;
-import restx.plugins.*;
-import restx.shell.*;
-
-import java.io.*;
-import java.net.URL;
-import java.nio.file.FileVisitResult;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.SimpleFileVisitor;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.util.ArrayList;
-import java.util.List;
-
-import static java.util.Arrays.asList;
-
-/**
- * User: xavierhanin
- * Date: 4/10/13
- * Time: 8:53 PM
- */
-@Component
-public class DepsShellCommand extends StdShellCommand {
- private static final String MVN_COMMAND = "mvn";
-
- public DepsShellCommand() {
- super(ImmutableList.of("deps"), "deps related commands: install / update / manage app dependencies");
- }
-
- @Override
- protected String resourceMan() {
- return "restx/core/shell/deps.man";
- }
-
- @Override
- protected Optional extends ShellCommandRunner> doMatch(String line) {
- List args = splitArgs(line);
-
- if (args.size() < 2) {
- return Optional.absent();
- }
-
- switch (args.get(1)) {
- case "install":
- return Optional.of(new InstallDepsCommandRunner());
- case "add":
- return Optional.of(new AddDepsCommandRunner(args));
- }
-
- return Optional.absent();
- }
-
- @Override
- public Iterable getCompleters() {
- return ImmutableList.of(new ArgumentCompleter(
- new StringsCompleter("deps"), new StringsCompleter("install", "add")));
- }
-
- public static class InstallDepsCommandRunner implements ShellCommandRunner {
-
- @Override
- public void run(RestxShell shell) throws Exception {
- Optional moduleDescriptorTypeWithExistingFileOpt = ModuleDescriptorType.firstModuleDescriptorTypeWithExistingFile(shell.currentLocation());
- if(!moduleDescriptorTypeWithExistingFileOpt.isPresent()) {
- throw new IllegalStateException(
- "md.restx.json file not found in " + shell.currentLocation() + "." +
- " It is required to perform deps management");
- }
-
- ModuleDescriptorType moduleDescriptorTypeWithExistingFile = moduleDescriptorTypeWithExistingFileOpt.get();
- if(ModuleDescriptorType.RESTX.equals(moduleDescriptorTypeWithExistingFile)) {
- shell.println("installing deps using restx module descriptor...");
- installDepsFromModuleDescriptor(shell, ModuleDescriptorType.RESTX.resolveDescriptorFile(shell.currentLocation()));
- } else if(ModuleDescriptorType.MAVEN.equals(moduleDescriptorTypeWithExistingFile)) {
- shell.println("installing deps using maven descriptor...");
- installDepsFromMavenDescriptor(shell, ModuleDescriptorType.MAVEN.resolveDescriptorFile(shell.currentLocation()));
- } else if(ModuleDescriptorType.IVY.equals(moduleDescriptorTypeWithExistingFile)) {
- shell.println("installing deps using ivy descriptor...");
- installDepsFromIvyDescriptor(shell, ModuleDescriptorType.IVY.resolveDescriptorFile(shell.currentLocation()));
- } else {
- throw new IllegalArgumentException("Unsupported deps install for module type "+moduleDescriptorTypeWithExistingFile);
- }
-
- storeModuleDescriptorMD5File(shell, moduleDescriptorTypeWithExistingFile);
-
- shell.println("DONE");
- }
-
- private void installDepsFromModuleDescriptor(RestxShell shell, File mdFile) throws Exception {
- File tempFile = File.createTempFile("restx-md", ".ivy");
- try (FileInputStream is = new FileInputStream(mdFile)) {
- ModuleDescriptor descriptor = new RestxJsonSupport().parse(is);
- try (BufferedWriter w = Files.newWriter(tempFile,Charsets.UTF_8)) {
- new IvySupport().generate(descriptor, w);
- }
-
- installDepsFromIvyDescriptor(shell, tempFile);
- } finally {
- tempFile.delete();
- }
- }
-
- private void installDepsFromIvyDescriptor(RestxShell shell, File ivyFile) throws Exception {
- Ivy ivy = ShellIvy.loadIvy(shell);
-
- shell.println("resolving dependencies...");
- ResolveReport resolveReport = ivy.resolve(ivyFile);
-
- shell.println("synchronizing dependencies in " + shell.currentLocation().resolve("target/dependency") + " ...");
- ivy.retrieve(resolveReport.getModuleDescriptor().getModuleRevisionId(),
- new RetrieveOptions()
- .setDestArtifactPattern(
- shell.currentLocation().toAbsolutePath() + "/target/dependency/[artifact]-[revision](-[classifier]).[ext]")
- .setSync(true)
- );
- }
-
- private void installDepsFromMavenDescriptor(RestxShell shell, File pomFile) throws Exception {
- AppSettings appSettings = shell.getFactory().getComponent(AppSettings.class);
-
- Path dependenciesDir = Paths.get(appSettings.targetDependency());
-
- // Emptying target dependencies directory first
- if(dependenciesDir.toFile().exists()) {
- java.nio.file.Files.walkFileTree(dependenciesDir, new SimpleFileVisitor() {
- @Override
- public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
- java.nio.file.Files.delete(file);
- return FileVisitResult.CONTINUE;
- }
- @Override
- public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
- java.nio.file.Files.delete(dir);
- return FileVisitResult.CONTINUE;
- }
- });
- }
-
- dependenciesDir.toFile().mkdirs();
-
- // Then copying dependencies through copy-dependencies plugin
- ProcessBuilder mavenCmd = new ProcessBuilder(
- MVN_COMMAND, "org.apache.maven.plugins:maven-dependency-plugin:3.0.1:copy-dependencies",
- "-DoutputDirectory=" + dependenciesDir.toAbsolutePath(), "-DincludeScope=runtime"
- );
-
- shell.println("Executing `"+mavenCmd+"` ...");
- try {
- mavenCmd.redirectErrorStream(true)
- .redirectOutput(ProcessBuilder.Redirect.INHERIT)
- .directory(shell.currentLocation().toFile().getAbsoluteFile())
- .start()
- .waitFor();
- } catch(IOException e) {
- if(e.getMessage().startsWith(String.format("Cannot run program \"%s\"", MVN_COMMAND))) {
- shell.println("Looks like mvn is not installed here ... trying to fallback installing pom.xml file with Ivy...");
- installDepsFromIvyDescriptor(shell, pomFile);
- } else {
- Throwables.propagate(e);
- }
- }
- }
-
- private static void storeModuleDescriptorMD5File(RestxShell shell, ModuleDescriptorType mdType) throws IOException {
- File mdFile = mdType.resolveDescriptorFile(shell.currentLocation());
- File md5File = ModuleDescriptorType.MAVEN.resolveDescriptorMd5File(shell.currentLocation());
-
- shell.println(String.format("Storing md5 file %s for module descriptor %s...", md5File.getAbsolutePath(), mdFile.getAbsolutePath()));
- Files.write(Files.hash(mdFile, Hashing.md5()).toString(), md5File, Charsets.UTF_8);
- }
- }
-
- static class AddDepsCommandRunner implements ShellCommandRunner {
- private final String scope;
- private Optional> pluginIds;
-
- public AddDepsCommandRunner(List args) {
- args = new ArrayList<>(args);
- if (args.size() > 2
- && args.get(2).startsWith("scope:")) {
- scope = args.get(2).substring("scope:".length());
- args.remove(2);
- } else {
- scope = "compile";
- }
-
- if (args.size() > 2) {
- pluginIds = Optional.>of(new ArrayList<>(args.subList(2, args.size())));
- } else {
- pluginIds = Optional.absent();
- }
- }
-
- @Override
- public void run(RestxShell shell) throws Exception {
- File mdFile = ModuleDescriptorType.RESTX.resolveDescriptorFile(shell.currentLocation());
- if (!mdFile.exists()) {
- throw new IllegalStateException(
- "md.restx.json file not found in " + shell.currentLocation() + "." +
- " It is required to perform deps management");
- }
-
- if (!pluginIds.isPresent()) {
- ModulesManager modulesManager = new ModulesManager(
- new URL("http://restx.io/modules"), ShellIvy.loadIvy(shell));
-
- shell.println("looking for plugins...");
- List plugins = modulesManager.searchModules("category=app");
-
- shell.printIn("found " + plugins.size() + " available plugins", RestxShell.AnsiCodes.ANSI_CYAN);
- shell.println("");
-
- for (int i = 0; i < plugins.size(); i++) {
- restx.plugins.ModuleDescriptor plugin = plugins.get(i);
- shell.printIn(String.format(" [%3d] %s%n", i + 1, plugin.getId()), RestxShell.AnsiCodes.ANSI_PURPLE);
- shell.println("\t\t" + plugin.getDescription());
- }
-
- String sel = shell.ask("Which plugin would you like to add (eg '1 3 5')? \n" +
- "You can also provide a plugin id in the form ::\n" +
- " plugin to install: ", "");
- Iterable selected = Splitter.on(" ").trimResults().omitEmptyStrings().split(sel);
- List ids = new ArrayList<>();
- for (String s : selected) {
- if (CharMatcher.DIGIT.matchesAllOf(s)) {
- ids.add(plugins.get(Integer.parseInt(s)).getId());
- } else {
- ids.add(s);
- }
- }
-
- pluginIds = Optional.of(ids);
- }
-
- ModuleDescriptor descriptor;
- try (FileInputStream is = new FileInputStream(mdFile)) {
- descriptor = new RestxJsonSupport().parse(is).getParsedModuleDescriptor();
-
- for (String s : pluginIds.get()) {
- descriptor = descriptor.concatDependency(scope, new ModuleDependency(GAV.parse(s)));
- }
- }
- try (Writer w = Files.newWriter(mdFile, Charsets.UTF_8)) {
- shell.println("updating " + mdFile);
- new RestxJsonSupport().generate(descriptor, w);
- }
-
- for (Path mod : RestxBuild.resolveForeignModuleDescriptorsIn(shell.currentLocation())) {
- shell.printIn("updating " + mod, RestxShell.AnsiCodes.ANSI_PURPLE);
- shell.println("");
- RestxBuild.convert(mdFile.toPath(), mod);
- }
- }
- }
-
- public static boolean depsUpToDate(RestxShell shell) {
- Optional moduleDescriptorTypeWithExistingFileOpt = ModuleDescriptorType.firstModuleDescriptorTypeWithExistingFile(shell.currentLocation());
- if(!moduleDescriptorTypeWithExistingFileOpt.isPresent()) {
- // no dependency management at all
- return true;
- }
-
- ModuleDescriptorType moduleDescriptorTypeWithExistingFile = moduleDescriptorTypeWithExistingFileOpt.get();
- File descriptorFile = moduleDescriptorTypeWithExistingFile.resolveDescriptorFile(shell.currentLocation());
- File moduleDescriptorMd5 = moduleDescriptorTypeWithExistingFile.resolveDescriptorMd5File(shell.currentLocation());
- if(!moduleDescriptorMd5.exists()) {
- return false;
- }
-
- try {
- String md5 = Files.hash(descriptorFile, Hashing.md5()).toString();
- return md5.equals(Files.toString(moduleDescriptorMd5, Charsets.UTF_8));
- } catch (IOException e) {
- return false;
- }
- }
-}
diff --git a/restx-core-shell/src/main/java/restx/core/shell/HashShellCommand.java b/restx-core-shell/src/main/java/restx/core/shell/HashShellCommand.java
deleted file mode 100644
index fd9a0382f..000000000
--- a/restx-core-shell/src/main/java/restx/core/shell/HashShellCommand.java
+++ /dev/null
@@ -1,100 +0,0 @@
-package restx.core.shell;
-
-import com.google.common.base.CharMatcher;
-import com.google.common.base.Charsets;
-import com.google.common.base.Optional;
-import com.google.common.base.Splitter;
-import com.google.common.collect.ImmutableList;
-import com.google.common.hash.Hashing;
-import com.google.common.io.Files;
-import jline.console.completer.ArgumentCompleter;
-import jline.console.completer.Completer;
-import jline.console.completer.StringsCompleter;
-import org.apache.ivy.Ivy;
-import org.apache.ivy.core.report.ResolveReport;
-import org.apache.ivy.core.retrieve.RetrieveOptions;
-import org.mindrot.jbcrypt.BCrypt;
-import restx.build.*;
-import restx.factory.Component;
-import restx.plugins.ModulesManager;
-import restx.shell.RestxShell;
-import restx.shell.ShellCommandRunner;
-import restx.shell.ShellIvy;
-import restx.shell.StdShellCommand;
-
-import java.io.*;
-import java.net.URL;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.List;
-
-import static java.util.Arrays.asList;
-
-/**
- * User: xavierhanin
- * Date: 4/10/13
- * Time: 8:53 PM
- */
-@Component
-public class HashShellCommand extends StdShellCommand {
- public HashShellCommand() {
- super(ImmutableList.of("hash"), "hash commands, to easily generate password hashes");
- }
-
- @Override
- protected String resourceMan() {
- return "restx/core/shell/hash.man";
- }
-
- @Override
- protected Optional extends ShellCommandRunner> doMatch(String line) {
- List args = splitArgs(line);
-
- if (args.size() < 3) {
- return Optional.absent();
- }
-
- return Optional.of(new HashCommandRunner(args.get(1), args.get(2)));
- }
-
- @Override
- public Iterable getCompleters() {
- return ImmutableList.of(new ArgumentCompleter(
- new StringsCompleter("hash"),
- new StringsCompleter("md5", "sha1", "bcrypt", "md5+bcrypt", "sha1+bcrypt")));
- }
-
- private class HashCommandRunner implements ShellCommandRunner {
- private final String hash;
- private final String plaintext;
-
- public HashCommandRunner(String hash, String plaintext) {
- this.hash = hash;
- this.plaintext = plaintext;
- }
-
- @Override
- public void run(RestxShell shell) throws Exception {
- switch (hash) {
- case "md5":
- shell.println(Hashing.md5().hashString(plaintext, Charsets.UTF_8).toString());
- break;
- case "sha1":
- shell.println(Hashing.sha1().hashString(plaintext, Charsets.UTF_8).toString());
- break;
- case "bcrypt":
- shell.println(BCrypt.hashpw(plaintext, BCrypt.gensalt()));
- break;
- case "md5+bcrypt":
- shell.println(BCrypt.hashpw(Hashing.md5().hashString(plaintext, Charsets.UTF_8).toString(), BCrypt.gensalt()));
- break;
- case "sha1+bcrypt":
- shell.println(BCrypt.hashpw(Hashing.sha1().hashString(plaintext, Charsets.UTF_8).toString(), BCrypt.gensalt()));
- break;
- default:
- shell.printIn("unknown hash function: " + hash, RestxShell.AnsiCodes.ANSI_RED);
- shell.println("");
- }
- }
- }
-}
diff --git a/restx-core-shell/src/main/java/restx/core/shell/ModuleDescriptorType.java b/restx-core-shell/src/main/java/restx/core/shell/ModuleDescriptorType.java
deleted file mode 100644
index e33c04d46..000000000
--- a/restx-core-shell/src/main/java/restx/core/shell/ModuleDescriptorType.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package restx.core.shell;
-
-import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
-import com.google.common.collect.FluentIterable;
-
-import java.io.File;
-import java.nio.file.Path;
-import java.util.Arrays;
-
-public enum ModuleDescriptorType {
- RESTX("md.restx.json"), MAVEN("pom.xml"), IVY("module.ivy");
-
- private String descriptorFileName;
-
- ModuleDescriptorType(String descriptorFileName) {
- this.descriptorFileName = descriptorFileName;
- }
-
- public String getDescriptorFileName() {
- return descriptorFileName;
- }
-
- public File resolveDescriptorFile(Path inDirectory) {
- return inDirectory.resolve(this.getDescriptorFileName()).toFile();
- }
-
- public File resolveDescriptorMd5File(Path inDirectory) {
- return inDirectory.resolve(String.format("target/dependency/%s.md5", this.getDescriptorFileName())).toFile();
- }
-
- public static Optional firstModuleDescriptorTypeWithExistingFile(final Path inDirectory) {
- return FluentIterable
- .from(Arrays.asList(ModuleDescriptorType.RESTX, ModuleDescriptorType.MAVEN))
- .filter(new Predicate() {
- @Override
- public boolean apply(ModuleDescriptorType mdType) {
- return mdType.resolveDescriptorFile(inDirectory).exists();
- }
- }).first();
- }
-
-}
diff --git a/restx-core-shell/src/main/java/restx/core/shell/RestxArchive.java b/restx-core-shell/src/main/java/restx/core/shell/RestxArchive.java
deleted file mode 100644
index 242b782c9..000000000
--- a/restx-core-shell/src/main/java/restx/core/shell/RestxArchive.java
+++ /dev/null
@@ -1,171 +0,0 @@
-package restx.core.shell;
-
-import com.google.common.base.Splitter;
-import com.google.common.base.Throwables;
-import com.google.common.collect.Iterables;
-import restx.AppSettings;
-import restx.build.RestxBuild;
-
-import java.io.*;
-import java.nio.file.*;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.util.*;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-import java.util.jar.JarOutputStream;
-
-/**
- * @author fcamblor
- */
-public class RestxArchive {
-
- private static final String CHROOT = "META-INF/restx/app/";
- private Path jarFile;
-
- public RestxArchive(Path jarFile) {
- this.jarFile = jarFile;
- }
-
- private static class JarCopierFileVisitor extends SimpleFileVisitor {
- private final Path startingDirectory;
- private final String targetDirPrefix;
- private List excludes;
- private final JarOutputStream jarOS;
-
- private JarCopierFileVisitor(Path startingDirectory, JarOutputStream jarOS, String targetDirPrefix, List excludes) {
- this.startingDirectory = startingDirectory;
- this.jarOS = jarOS;
- this.targetDirPrefix = targetDirPrefix;
- this.excludes = excludes;
- }
-
- @Override
- public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
- super.preVisitDirectory(dir, attrs);
-
- String directoryRelativizedName = startingDirectory.relativize(dir).toString().replace("\\", "/");
- if(!directoryRelativizedName.isEmpty()) {
- if(!directoryRelativizedName.endsWith("/")) {
- directoryRelativizedName += "/";
- }
-
- for(String exclude : excludes){
- if(directoryRelativizedName.startsWith(exclude)){
- return FileVisitResult.SKIP_SUBTREE;
- }
- }
-
- String targetDirectoryPath = targetDirPrefix + directoryRelativizedName;
-
- JarEntry dirEntry = new JarEntry(targetDirectoryPath);
- dirEntry.setTime(Files.getLastModifiedTime(dir).toMillis());
- jarOS.putNextEntry(dirEntry);
- jarOS.closeEntry();
- }
-
- return FileVisitResult.CONTINUE;
- }
-
- @Override
- public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
- super.visitFile(file, attrs);
-
- copyFileToJar(jarOS, startingDirectory, targetDirPrefix, file);
-
- return FileVisitResult.CONTINUE;
- }
- }
-
- private static void createJarDirIfNotExists(JarOutputStream jarOS, Path rootDir, String path) throws IOException {
- if(!Files.exists(rootDir.resolve(path))){
- JarEntry dirEntry = new JarEntry(path+"/");
- jarOS.putNextEntry(dirEntry);
- jarOS.closeEntry();
- }
- }
-
- private static void copyFileToJar(JarOutputStream jarOS, Path rootDir, String targetDirPrefix, Path file) throws IOException {
- JarEntry fileEntry = new JarEntry(targetDirPrefix + rootDir.relativize(file).toString());
-
- try { fileEntry.setTime(Files.getLastModifiedTime(file).toMillis()); }
- catch (IOException e) {}
-
- jarOS.putNextEntry(fileEntry);
- Files.copy(file, jarOS);
- jarOS.closeEntry();
- }
-
- public void pack(Path workingDirectory, final Path targetClassesDirectory, List packagingExcludes) {
- try(final JarOutputStream jarOS = new JarOutputStream(new FileOutputStream(jarFile.toFile()))) {
-
- // Generating md.restx.json if it doesn't exist yet
- // Because a restx archive without this descriptor won't be considered as valid restx archive
- Path md = workingDirectory.resolve("md.restx.json");
- boolean generatedMd = false;
- if(!Files.exists(md)){
- List foreignModuleDescriptors = RestxBuild.resolveForeignModuleDescriptorsIn(workingDirectory);
- if(!foreignModuleDescriptors.isEmpty()) {
- Path firstModuleDescriptor = Iterables.getFirst(foreignModuleDescriptors, null);
- RestxBuild.convert(firstModuleDescriptor, md);
- generatedMd = true;
- } else {
- throw new RuntimeException("Project descriptor (either a md.restx.json, or a foreign descriptor (pom, ivy, ...) file) is missing !");
- }
- }
-
- try {
- Files.walkFileTree(targetClassesDirectory, new JarCopierFileVisitor(targetClassesDirectory, jarOS, "", Collections.emptyList()));
-
- // Ensuring CHROOT is made available in target jar
- String path = "";
- for(String chrootChunk : Splitter.on("/").split(CHROOT)){
- if(!chrootChunk.isEmpty()) {
- path += chrootChunk;
- createJarDirIfNotExists(jarOS, targetClassesDirectory, path);
- path += "/";
- }
- }
-
- // Copying everything into CHROOT directory
- Files.walkFileTree(workingDirectory, new JarCopierFileVisitor(workingDirectory, jarOS, CHROOT, packagingExcludes));
- } finally {
- if(generatedMd) {
- md.toFile().delete();
- }
- }
- } catch (IOException e) {
- Throwables.propagate(e);
- }
- }
-
- public void unpack(Path destinationDirectory, AppSettings appSettings) {
- Path targetClassesDir = destinationDirectory.resolve(appSettings.targetClasses());
- try ( JarFile jar = new JarFile(jarFile.toFile()) ) {
- if(jar.getJarEntry(CHROOT+"md.restx.json") == null) {
- throw new IllegalArgumentException("File "+jarFile+" is not a restx archive (no md.restx.json file found) !");
- }
- for(Enumeration jarEntries = jar.entries(); jarEntries.hasMoreElements();){
- JarEntry entry = jarEntries.nextElement();
- String entryPath = entry.getName();
- if(!entry.isDirectory()) {
- Path destinationFile;
- // Unpacking chrooted files in app root directory..
- if(entryPath.startsWith(CHROOT)) {
- Path chrootedFile = destinationDirectory.resolve(entryPath.substring(CHROOT.length()));
- destinationFile = chrootedFile;
- // ... and unpacking other files in classes directory
- } else {
- destinationFile = targetClassesDir.resolve(entryPath);
- }
-
- com.google.common.io.Files.createParentDirs(destinationFile.toFile());
- try(InputStream jarInputStream = jar.getInputStream(entry)) {
- Files.copy(jarInputStream, destinationFile);
- }
- }
- }
- } catch (IOException e) {
- throw Throwables.propagate(e);
- }
- }
-}
diff --git a/restx-core-shell/src/main/java/restx/core/shell/ShellAppRunner.java b/restx-core-shell/src/main/java/restx/core/shell/ShellAppRunner.java
deleted file mode 100644
index 20661aad5..000000000
--- a/restx-core-shell/src/main/java/restx/core/shell/ShellAppRunner.java
+++ /dev/null
@@ -1,182 +0,0 @@
-package restx.core.shell;
-
-import com.google.common.base.Charsets;
-import com.google.common.base.Joiner;
-import com.google.common.io.Files;
-import restx.AppSettings;
-import restx.Apps;
-import restx.shell.RestxShell;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.FileVisitResult;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.SimpleFileVisitor;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import static restx.common.MoreFiles.copyDir;
-
-/**
- * User: xavierhanin
- * Date: 9/8/13
- * Time: 2:48 PM
- */
-public class ShellAppRunner {
- public static enum CompileMode {
- NO {
- @Override
- boolean compile(RestxShell shell, Path targetClasses, Path dependenciesDir, Path mainSources, Path mainResources, String className) throws IOException, InterruptedException {
- return true;
- }
- },
- RESOURCES_ONLY {
- @Override
- boolean compile(RestxShell shell, Path targetClasses, Path dependenciesDir, Path mainSources, Path mainResources, String className) throws IOException, InterruptedException {
- shell.print("copying resources...");
- copyDir(
- shell.currentLocation().resolve(mainResources),
- shell.currentLocation().resolve(targetClasses)
- );
- shell.printIn(" [DONE]", RestxShell.AnsiCodes.ANSI_GREEN);
- shell.println("");
- return true;
- }
- },
- MAIN_CLASS {
- @Override
- boolean compile(RestxShell shell, Path targetClasses, Path dependenciesDir, Path mainSources, Path mainResources, String className) throws IOException, InterruptedException {
- shell.print("compiling App...");
- shell.currentLocation().resolve(targetClasses).toFile().mkdirs();
- int compiled = new ProcessBuilder(
- "javac", "-cp", dependenciesDir + "/*", "-sourcepath", mainSources.toString(),
- "-d", targetClasses.toString(),
- mainSources.resolve(className.replace('.', '/') + ".java").toString())
- .redirectErrorStream(true)
- .redirectOutput(ProcessBuilder.Redirect.INHERIT)
- .directory(shell.currentLocation().toFile().getAbsoluteFile())
- .start()
- .waitFor();
- if (compiled != 0) {
- shell.printIn(" [ERROR]", RestxShell.AnsiCodes.ANSI_RED);
- shell.println("");
- return false;
- }
- shell.printIn(" [DONE]", RestxShell.AnsiCodes.ANSI_GREEN);
- shell.println("");
-
- shell.print("copying resources...");
- copyDir(
- shell.currentLocation().resolve(mainResources),
- shell.currentLocation().resolve(targetClasses)
- );
- shell.printIn(" [DONE]", RestxShell.AnsiCodes.ANSI_GREEN);
- shell.println("");
- return true;
- }
- },
- ALL {
- @Override
- boolean compile(RestxShell shell,
- Path targetClasses, Path dependenciesDir,
- final Path mainSources, Path mainResources,
- String className) throws IOException, InterruptedException {
- shell.print("compiling App...");
- shell.currentLocation().resolve(targetClasses).toFile().mkdirs();
- File currentDir = shell.currentLocation().toFile().getAbsoluteFile();
-
- final List sources = new ArrayList<>();
- java.nio.file.Files.walkFileTree(mainSources, new SimpleFileVisitor() {
- @Override
- public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
- if (file.toString().endsWith(".java")) {
- sources.add(file.toAbsolutePath().toString());
- }
- return FileVisitResult.CONTINUE;
- }
- });
- shell.printIn(" [" + sources.size() + " source files]", RestxShell.AnsiCodes.ANSI_CYAN);
- File classesFile = new File(currentDir, ".restx.classes");
- Files.write(Joiner.on("\n").join(sources), classesFile, Charsets.UTF_8);
- int compiled = new ProcessBuilder(
- "javac", "-cp", dependenciesDir + "/*", "-sourcepath", mainSources.toString(),
- "-d", targetClasses.toString(),
- "@" + classesFile.getName())
- .redirectErrorStream(true)
- .redirectOutput(ProcessBuilder.Redirect.INHERIT)
- .directory(currentDir)
- .start()
- .waitFor();
- classesFile.delete();
-
- if (compiled != 0) {
- shell.printIn(" [ERROR]", RestxShell.AnsiCodes.ANSI_RED);
- shell.println("");
- return false;
- }
- shell.printIn(" [DONE]", RestxShell.AnsiCodes.ANSI_GREEN);
- shell.println("");
-
- shell.print("copying resources...");
- copyDir(
- shell.currentLocation().resolve(mainResources),
- shell.currentLocation().resolve(targetClasses)
- );
- shell.printIn(" [DONE]", RestxShell.AnsiCodes.ANSI_GREEN);
- shell.println("");
- return true;
- }
- };
-
- abstract boolean compile(RestxShell shell, Path targetClasses, Path dependenciesDir, Path mainSources, Path mainResources, String className) throws IOException, InterruptedException;
-
- }
- private final AppSettings appSettings;
-
- private final String appClassName;
- private final CompileMode compile;
- private final boolean quiet;
- private final boolean daemon;
- private final List vmOptions;
-
- public ShellAppRunner(AppSettings appSettings, String appClassName, CompileMode compile,
- boolean quiet, boolean daemon, List vmOptions) {
- this.appSettings = appSettings;
- this.appClassName = appClassName;
- this.compile = compile;
- this.quiet = quiet;
- this.daemon = daemon;
- this.vmOptions = new ArrayList<>(vmOptions);
- }
-
- public void run(RestxShell shell) throws IOException, InterruptedException {
- Path targetClasses = Paths.get(appSettings.targetClasses());
- Path dependenciesDir = Paths.get(appSettings.targetDependency());
- Path mainSources = Paths.get(appSettings.mainSources());
- Path mainResources = Paths.get(appSettings.mainResources());
-
- if (!compile.compile(shell, targetClasses, dependenciesDir, mainSources, mainResources, appClassName)) return;
-
- shell.println("starting " + appClassName + "..." +
- (daemon ? " - type `stop` to stop it and go back to restx shell" : ""));
- vmOptions.add("-Drestx.app.package=" + appSettings.appPackage());
- Process run = Apps.with(appSettings)
- .run(shell.currentLocation().toFile(),
- targetClasses, dependenciesDir, vmOptions,
- appClassName, Collections.emptyList(), quiet);
-
- if (daemon) {
- while (!shell.ask("", "").equals("stop")) {
- shell.printIn("restx> unrecognized command - type `stop` to stop the app",
- RestxShell.AnsiCodes.ANSI_YELLOW);
- shell.println("");
- }
- run.destroy();
- }
- run.waitFor();
- }
-
-}
diff --git a/restx-core-shell/src/main/resources/restx/core/shell/app.man b/restx-core-shell/src/main/resources/restx/core/shell/app.man
deleted file mode 100644
index 478b3afae..000000000
--- a/restx-core-shell/src/main/resources/restx/core/shell/app.man
+++ /dev/null
@@ -1,112 +0,0 @@
-## app new
-
-`app new` command let you create a new restx app.
-
-It doesn't take any additional argument, it will ask for parameters to generate the app.
-
-## app compile
-
-Compile current application.
-
-This command uses javac to compile your application classes located in `src/main/java` and put compiled classes in
-`target/classes`.
-It uses dependencies located in `target/dependency`.
-
-Note: You need to be placed in a restx app root directory to run this command.
-
-## app generate-start-script []
-
-Generate a start script to run your application outside restx shell.
-
-This can be useful for production, it let you avoid to have a jvm running for the shell (which is the case when you use
-`app run`).
-
-The command actually generates 2 scripts: `start.sh` for *nix and `start.bat` for windows.
-
-You can optionally provide the fully qualified name of the main class, if you don't provide one restx will try to guess
-it.
-
-Note: You need to be placed in a restx app root directory to run this command.
-
-
-## app run [--quiet] [--fg] [-D=] [--mode=] [|]
-
-Run a restx application.
-
-Running a restx app is simply launching a java process taking all jars from `target/dependency` + classes
-from `target/classes` in classpath.
-
-It will run `deps install` if needed (if `md.restx.json` file has changed since last `deps install` call).
-If you prefer to use another dependency management mechanism, you just need to fill the `target/dependency` directory
-with all your dependencies jars before calling app run.
-
-Your app will be started in different modes depending on your working directory typology :
-- If sources are not found (in src/main/java), app will be forced in prod mode (no auto/hot compile).
-- If sources are found, main class will be compiled before running the app.
- It compiles only the main class because restx has auto compile feature, except in prod mode where it will compile all
- classes as with `app compile`.
-
-### Options
-
-`--quiet`
- do not show output in console. This is sometimes useful for performance reasons, console writing is synchronous and
- can thus slow down your application, especially if you run through a slow ssh connection.
-
-`--fg`
- by default app run the application in a separate process in the background. and wait for a `stop` command on the
- shell input. Sometimes you may prefer to join the sub process and do not wait for a stop command (eg in situations
- where you don't want to use shell input, like when running a restx app through batch script).
-
-`-D=`
- allow to set system properties for the app, which are simply passed as vm options to the sub process
-
-`--mode=`
- an easy way to set restx mode.
- It has the same effect as running -Drestx.mode=, except that in prod it also influence the way compilation is
- done (see above).
-
-`|`
- Either the fully qualified name of the main class to run,
- or a restx app directory name (restx app are located into your `${restx.home}/apps/` directory).
- Main class will be retrieved :
- - If provided as argument (main.class.Name)
- - By looking into md.restx.json file ("manifest.main.classname" property)
- - By guessing it from source files
-
-
-## app archive
-
-Create a restx archive from current working directory.
-A restx archive is a standard jar archive, with source (including assets) ressources located in `META-INF/restx/app/`
-folder.
-
-Purpose of these archives is to be easily deployable with the `app grab` command.
-They embed a restx module descriptor which will be used to provision dependencies before launching the restx app.
-
-``
- Path to generated restx archive vile.
-
-## app grab []
-
-Grab and unpack a restx archive/project into a directory, then change restx shell to this directory in order
-to easily chain this command with `app run` command.
-
-A restx archive is a standard jar archive, with sources (including assets) ressources located in `META-INF/restx/app/`
-folder.
-Note that a restx archive MUST contain a `META-INF/restx/app/md.restx.json` file in order to be considered valid.
-
-``
- different types of coordinates are available :
- - GIT url (pattern : [#[], for instance `git@github.com:foo/bar.git#v1.0`)
- Git repository will be cloned inside `destination` directory.
- Needs git executable to be available in your PATH.
- - Http/https url of a Restx archive.
- Archive classes will be unpacked into `/target/restx/classes/` directory,
- and `META-INF/restx/app/*` (including md.restx.json file) will be chrooted into `destination` directory.
- - GAV coordinates (pattern : ::)
- Archive classes will be unpacked into `/target/restx/classes/` directory,
- and `META-INF/restx/app/*` (including md.restx.json file) will be chrooted into `destination` directory.
-
-``
- destination where will reside your grabbed restx application working directory.
- If not set, `~/.restx/apps//` will be used.
diff --git a/restx-core-shell/src/main/resources/restx/core/shell/deps.man b/restx-core-shell/src/main/resources/restx/core/shell/deps.man
deleted file mode 100644
index f72686c68..000000000
--- a/restx-core-shell/src/main/resources/restx/core/shell/deps.man
+++ /dev/null
@@ -1,27 +0,0 @@
-## deps install
-
-Resolve dependencies declared in current module descriptor (in order: either `md.restx.json`, `pom.xml` or `module.ivy`),
-and synchronize them in `target/dependency` directory.
-
-For both `md.restx.json` and `module.ivy`, this command uses Apache Ivy under the hood to perform dependency resolution,
-using settings provided by restx. You can override these Ivy settings by placing a file named ivysettings.xml in your
-restx shell install location (usually `~/.restx`).
-
-For `pom.xml`, this command will use maven-dependency-plugin:copy-dependencies goal to perform dependency resolution.
-
-Note: You need to be placed in a restx app root directory to run this command.
-
-## deps add [scope:] [plugin.id]
-
-Declare new dependencies in your `md.restx.json` module descriptor, and update corresponding module descriptors
-(pom and/or ivy).
-
-The plugin id is given in Grails like notation: `::`. You can use http://search.maven.org to
-search for them and choose "Grails" on the module detail page to get the id.
-
-If you don't provide plugin id as a parameter to the command, the shell will provide a list of typical dependencies
-that can be added to a restx app.
-
-You can also provide a scope as parameter, using the `scope:` notation, eg `scope:runtime`.
-
-This command does not install the dependencies, use `deps install` command to install them.
\ No newline at end of file
diff --git a/restx-core-shell/src/main/resources/restx/core/shell/hash.man b/restx-core-shell/src/main/resources/restx/core/shell/hash.man
deleted file mode 100644
index 82a8dcf9e..000000000
--- a/restx-core-shell/src/main/resources/restx/core/shell/hash.man
+++ /dev/null
@@ -1,19 +0,0 @@
-## hash md5
-
-Computes the md5 of given plain text string
-
-## hash sha1
-
-Computes the sha1 of given plain text string
-
-## hash bcrypt
-
-bcrypt given plain text string
-
-## hash md5+bcrypt
-
-Hash with md5, and then bcrypt the given plain text password
-
-## hash sha1+bcrypt
-
-Hash with sha1, and then bcrypt the given plain text password
\ No newline at end of file
diff --git a/restx-core-shell/src/main/resources/templates/root/grunt-bower/ui/build.bat b/restx-core-shell/src/main/resources/templates/root/grunt-bower/ui/build.bat
deleted file mode 100644
index d2f6207b8..000000000
--- a/restx-core-shell/src/main/resources/templates/root/grunt-bower/ui/build.bat
+++ /dev/null
@@ -1,6 +0,0 @@
-REM This script is used to build the front app and put it in the dist directory.
-
-npm install
-bower install
-grunt test
-grunt build
diff --git a/restx-core-shell/src/main/resources/templates/root/grunt-bower/ui/build.sh b/restx-core-shell/src/main/resources/templates/root/grunt-bower/ui/build.sh
deleted file mode 100644
index 0df170cf2..000000000
--- a/restx-core-shell/src/main/resources/templates/root/grunt-bower/ui/build.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/sh
-
-# This script is used to build the front app and put it in the dist directory.
-
-npm install
-bower install
-grunt test
-grunt build
diff --git a/restx-core-shell/src/main/resources/templates/root/main/_pom.xml b/restx-core-shell/src/main/resources/templates/root/main/_pom.xml
deleted file mode 100644
index 58bb81859..000000000
--- a/restx-core-shell/src/main/resources/templates/root/main/_pom.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
- 4.0.0
-
- {{groupId}}
- {{artifactId}}-parent
- {{version}}
- pom
-
-
- ui
- srv
-
-
\ No newline at end of file
diff --git a/restx-core-shell/src/main/resources/templates/root/main/ui/_pom.xml b/restx-core-shell/src/main/resources/templates/root/main/ui/_pom.xml
deleted file mode 100644
index 8b1201153..000000000
--- a/restx-core-shell/src/main/resources/templates/root/main/ui/_pom.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-
-
- 4.0.0
-
- {{groupId}}
- {{artifactId}}-ui
- {{version}}
- pom
-
-
-
-
- org.codehaus.gmaven
- groovy-maven-plugin
- 2.0
-
-
- compile
-
- execute
-
-
-
- ${project.basedir}
- build
-
-
-
-
-
-
-
- maven-assembly-plugin
-
-
- distro-assembly
- package
-
- single
-
-
- false
-
- package-web-dist
-
-
-
-
-
-
- io.restx
- restx-maven-assemblies
- 1.0
-
-
-
-
-
-
\ No newline at end of file
diff --git a/restx-core-shell/src/main/resources/templates/root/no-node/ui/build.bat b/restx-core-shell/src/main/resources/templates/root/no-node/ui/build.bat
deleted file mode 100644
index f49d8ccf5..000000000
--- a/restx-core-shell/src/main/resources/templates/root/no-node/ui/build.bat
+++ /dev/null
@@ -1,3 +0,0 @@
-REM This script is used to build the front app and put it in the dist directory.
-
-xcopy app dist /s /e /i /y
\ No newline at end of file
diff --git a/restx-core-shell/src/main/resources/templates/root/no-node/ui/build.sh b/restx-core-shell/src/main/resources/templates/root/no-node/ui/build.sh
deleted file mode 100644
index 876d7b562..000000000
--- a/restx-core-shell/src/main/resources/templates/root/no-node/ui/build.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/sh
-
-# This script is used to build the front app and put it in the dist directory.
-
-rm -rf dist
-cp -R app dist
\ No newline at end of file
diff --git a/restx-core-shell/src/main/resources/templates/srv/helloResource/data/users.json b/restx-core-shell/src/main/resources/templates/srv/helloResource/data/users.json
deleted file mode 100644
index 834e03c4b..000000000
--- a/restx-core-shell/src/main/resources/templates/srv/helloResource/data/users.json
+++ /dev/null
@@ -1,4 +0,0 @@
-[
- {"name":"user1", "roles": ["hello"]},
- {"name":"user2", "roles": []}
-]
\ No newline at end of file
diff --git a/restx-core-shell/src/main/resources/templates/srv/helloResource/src/main/java/$packagePath$/_Roles.java b/restx-core-shell/src/main/resources/templates/srv/helloResource/src/main/java/$packagePath$/_Roles.java
deleted file mode 100644
index d3b405760..000000000
--- a/restx-core-shell/src/main/resources/templates/srv/helloResource/src/main/java/$packagePath$/_Roles.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package {{mainPackage}};
-
-/**
- * A list of roles for the application.
- *
- * We don't use an enum here because it must be used inside an annotation.
- */
-public final class Roles {
- public static final String HELLO_ROLE = "hello";
-}
diff --git a/restx-core-shell/src/main/resources/templates/srv/helloResource/src/main/java/$packagePath$/domain/_Message.java b/restx-core-shell/src/main/resources/templates/srv/helloResource/src/main/java/$packagePath$/domain/_Message.java
deleted file mode 100644
index 3da2d6ee6..000000000
--- a/restx-core-shell/src/main/resources/templates/srv/helloResource/src/main/java/$packagePath$/domain/_Message.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package {{mainPackage}}.domain;
-
-public class Message {
- private String message;
-
- public String getMessage() {
- return message;
- }
-
- public Message setMessage(final String message) {
- this.message = message;
- return this;
- }
-
- @Override
- public String toString() {
- return "Message{" +
- "message='" + message + '\'' +
- '}';
- }
-}
diff --git a/restx-core-shell/src/main/resources/templates/srv/helloResource/src/main/java/$packagePath$/rest/_HelloResource.java b/restx-core-shell/src/main/resources/templates/srv/helloResource/src/main/java/$packagePath$/rest/_HelloResource.java
deleted file mode 100644
index a14d34b4f..000000000
--- a/restx-core-shell/src/main/resources/templates/srv/helloResource/src/main/java/$packagePath$/rest/_HelloResource.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package {{mainPackage}}.rest;
-
-import {{mainPackage}}.domain.Message;
-import {{mainPackage}}.Roles;
-import org.joda.time.DateTime;
-import restx.annotations.GET;
-import restx.annotations.POST;
-import restx.annotations.RestxResource;
-import restx.factory.Component;
-import restx.security.PermitAll;
-import restx.security.RolesAllowed;
-import restx.security.RestxSession;
-
-import javax.validation.constraints.NotNull;
-
-@Component @RestxResource
-public class HelloResource {
-
- /**
- * Say hello to currently logged in user.
- *
- * Authorized only for principals with Roles.HELLO_ROLE role.
- *
- * @return a Message to say hello
- */
- @GET("/message")
- @RolesAllowed(Roles.HELLO_ROLE)
- public Message sayHello() {
- return new Message().setMessage(String.format(
- "hello %s, it's %s",
- RestxSession.current().getPrincipal().get().getName(),
- DateTime.now().toString("HH:mm:ss")));
- }
-
- /**
- * Say hello to anybody.
- *
- * Does not require authentication.
- *
- * @return a Message to say hello
- */
- @GET("/hello")
- @PermitAll
- public Message helloPublic(String who) {
- return new Message().setMessage(String.format(
- "hello %s, it's %s",
- who, DateTime.now().toString("HH:mm:ss")));
- }
-
- public static class MyPOJO {
- @NotNull
- String value;
- public String getValue(){ return value; }
- public void setValue(String value){ this.value = value; }
- }
- @POST("/mypojo")
- @PermitAll
- public MyPOJO helloPojo(MyPOJO pojo){
- pojo.setValue("hello "+pojo.getValue());
- return pojo;
- }
-}
diff --git a/restx-core-shell/src/main/resources/templates/srv/helloResource/src/test/java/$packagePath$/rest/_HelloResourceSpecTest.java b/restx-core-shell/src/main/resources/templates/srv/helloResource/src/test/java/$packagePath$/rest/_HelloResourceSpecTest.java
deleted file mode 100644
index 9b1206dbf..000000000
--- a/restx-core-shell/src/main/resources/templates/srv/helloResource/src/test/java/$packagePath$/rest/_HelloResourceSpecTest.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package {{mainPackage}}.rest;
-
-import {{mainPackage}}.AppServer;
-import org.junit.runner.RunWith;
-import restx.tests.RestxSpecTestsRunner;
-import restx.tests.FindSpecsIn;
-
-@RunWith(RestxSpecTestsRunner.class)
-@FindSpecsIn("specs/hello")
-public class HelloResourceSpecTest {
-
- /**
- * Useless, thanks to both @RunWith(RestxSpecTestsRunner.class) & @FindSpecsIn()
- *
- * @Rule
- * public RestxSpecRule rule = new RestxSpecRule();
- *
- * @Test
- * public void test_spec() throws Exception {
- * rule.runTest(specTestPath);
- * }
- */
-}
diff --git a/restx-core-shell/src/main/resources/templates/srv/helloResource/src/test/resources/specs/hello/_should_admin_say_hello.spec.yaml b/restx-core-shell/src/main/resources/templates/srv/helloResource/src/test/resources/specs/hello/_should_admin_say_hello.spec.yaml
deleted file mode 100644
index 1b7b8f0f9..000000000
--- a/restx-core-shell/src/main/resources/templates/srv/helloResource/src/test/resources/specs/hello/_should_admin_say_hello.spec.yaml
+++ /dev/null
@@ -1,10 +0,0 @@
-title: should admin say hello
-given:
- - time: 2013-08-28T01:18:00.822+02:00
- - uuids: [ "e2b4430f-9541-4602-9a3a-413d17c56a6b" ]
-wts:
- - when: |
- GET message
- $RestxSession: {"_expires":"2013-09-27T01:18:00.822+02:00","principal":"admin","sessionKey":"e2b4430f-9541-4602-9a3a-413d17c56a6b"}
- then: |
- {"message":"hello admin, it's 01:18:00"}
diff --git a/restx-core-shell/src/main/resources/templates/srv/helloResource/src/test/resources/specs/hello/_should_anyone_say_hello.spec.yaml b/restx-core-shell/src/main/resources/templates/srv/helloResource/src/test/resources/specs/hello/_should_anyone_say_hello.spec.yaml
deleted file mode 100644
index 29b6faca3..000000000
--- a/restx-core-shell/src/main/resources/templates/srv/helloResource/src/test/resources/specs/hello/_should_anyone_say_hello.spec.yaml
+++ /dev/null
@@ -1,8 +0,0 @@
-title: should admin say hello
-given:
- - time: 2013-08-28T01:18:00.822+02:00
-wts:
- - when: |
- GET hello?who=xavier
- then: |
- {"message":"hello xavier, it's 01:18:00"}
diff --git a/restx-core-shell/src/main/resources/templates/srv/helloResource/src/test/resources/specs/hello/_should_missing_value_triggers_validation_error.spec.yaml b/restx-core-shell/src/main/resources/templates/srv/helloResource/src/test/resources/specs/hello/_should_missing_value_triggers_validation_error.spec.yaml
deleted file mode 100644
index d0c6323ca..000000000
--- a/restx-core-shell/src/main/resources/templates/srv/helloResource/src/test/resources/specs/hello/_should_missing_value_triggers_validation_error.spec.yaml
+++ /dev/null
@@ -1,17 +0,0 @@
-title: should missing post value triggers a validation error
-given:
- - time: 2013-08-28T01:18:00.822+02:00
- - uuids: [ "e2b4430f-9541-4602-9a3a-413d17c56a6b" ]
-wts:
- - when: |
- POST mypojo
- $RestxSession: {"_expires":"2013-09-27T01:18:00.822+02:00","principal":"user1","sessionKey":"e2b4430f-9541-4602-9a3a-413d17c56a6b"}
- {}
- then: |
- 400
- - when: |
- POST mypojo
- $RestxSession: {"_expires":"2013-09-27T01:18:00.822+02:00","principal":"user1","sessionKey":"e2b4430f-9541-4602-9a3a-413d17c56a6b"}
- {"value":"world"}
- then: |
- {"value":"hello world"}
diff --git a/restx-core-shell/src/main/resources/templates/srv/helloResource/src/test/resources/specs/hello/_should_user1_say_hello.spec.yaml b/restx-core-shell/src/main/resources/templates/srv/helloResource/src/test/resources/specs/hello/_should_user1_say_hello.spec.yaml
deleted file mode 100644
index 791a3a277..000000000
--- a/restx-core-shell/src/main/resources/templates/srv/helloResource/src/test/resources/specs/hello/_should_user1_say_hello.spec.yaml
+++ /dev/null
@@ -1,10 +0,0 @@
-title: should user1 say hello
-given:
- - time: 2013-08-28T01:18:00.822+02:00
- - uuids: [ "e2b4430f-9541-4602-9a3a-413d17c56a6b" ]
-wts:
- - when: |
- GET message
- $RestxSession: {"_expires":"2013-09-27T01:18:00.822+02:00","principal":"user1","sessionKey":"e2b4430f-9541-4602-9a3a-413d17c56a6b"}
- then: |
- {"message":"hello user1, it's 01:18:00"}
diff --git a/restx-core-shell/src/main/resources/templates/srv/helloResource/src/test/resources/specs/hello/_should_user2_not_say_hello.spec.yaml b/restx-core-shell/src/main/resources/templates/srv/helloResource/src/test/resources/specs/hello/_should_user2_not_say_hello.spec.yaml
deleted file mode 100644
index ead5af8d0..000000000
--- a/restx-core-shell/src/main/resources/templates/srv/helloResource/src/test/resources/specs/hello/_should_user2_not_say_hello.spec.yaml
+++ /dev/null
@@ -1,10 +0,0 @@
-title: should user2 not say hello
-given:
- - time: 2013-08-28T01:19:44.770+02:00
- - uuids: [ "56f71fcc-42d3-422f-9458-8ad37fc4a0b5" ]
-wts:
- - when: |
- GET message
- $RestxSession: {"_expires":"2013-09-27T01:19:44.770+02:00","principal":"user2","sessionKey":"56f71fcc-42d3-422f-9458-8ad37fc4a0b5"}
- then: |
- 403
diff --git a/restx-core-shell/src/main/resources/templates/srv/main/_md.restx.json b/restx-core-shell/src/main/resources/templates/srv/main/_md.restx.json
deleted file mode 100644
index 3cbabd00e..000000000
--- a/restx-core-shell/src/main/resources/templates/srv/main/_md.restx.json
+++ /dev/null
@@ -1,45 +0,0 @@
-{
- "module": "{{groupId}}:{{artifactId}}:{{version}}",
- "packaging": "war",
-
- "properties": {
- "java.version": "{{javaVersion}}",
- "restx.version": "{{restxVersion}}"{{#useSrvuiLayout}},
- "project.war.overlay.groupId": "{{groupId}}",
- "project.war.overlay.artifactId": "{{artifactId}}"{{/useSrvuiLayout}}
- },
- "fragments": {
- "maven": [
- "classpath:///restx/build/fragments/maven/javadoc-apidoclet.xml"{{#useSrvuiLayout}},
- "classpath:///restx/build/fragments/maven/war-overlay-resources.xml"
-{{/useSrvuiLayout}}
- ]
- },
- "dependencies": {
- "compile": [
- "io.restx:restx-core:${restx.version}",
- "io.restx:restx-security-basic:${restx.version}",
- "io.restx:restx-core-annotation-processor:${restx.version}",
- "io.restx:restx-factory:${restx.version}",
- "io.restx:restx-factory-admin:${restx.version}",
- "io.restx:restx-validation:${restx.version}",
- "io.restx:restx-monitor-codahale:${restx.version}",
- "io.restx:restx-monitor-admin:${restx.version}",
- "io.restx:restx-log-admin:${restx.version}",
- "io.restx:restx-i18n-admin:${restx.version}",
-{{#includeStatsModule}}
- "io.restx:restx-stats-admin:${restx.version}",
-{{/includeStatsModule}}
- "io.restx:restx-servlet:${restx.version}",
- "io.restx:restx-server-jetty8:${restx.version}!optional",
- "io.restx:restx-apidocs:${restx.version}",
- "io.restx:restx-specs-admin:${restx.version}",
- "io.restx:restx-admin:${restx.version}",
- "ch.qos.logback:logback-classic:1.0.13"
- ],
- "test": [
- "io.restx:restx-specs-tests:${restx.version}",
- "junit:junit:4.11"
- ]
- }
-}
diff --git a/restx-core-shell/src/main/resources/templates/srv/main/data/credentials.json b/restx-core-shell/src/main/resources/templates/srv/main/data/credentials.json
deleted file mode 100644
index c1a4fcf53..000000000
--- a/restx-core-shell/src/main/resources/templates/srv/main/data/credentials.json
+++ /dev/null
@@ -1,12 +0,0 @@
-{
- "//": "lines with // keys are just comments (we don't have real comments in json)",
- "//": "this file stores password passed through md5+bcrypt hash",
- "//": "you can use `restx hash md5+bcrypt {password}` shell command to get hashed passwords to put here",
-
- "//": "to help startup with restx, there are comments with clear text passwords,",
- "//": "which should obviously not be stored here.",
- "user1": "$2a$10$iZluFUJShbjb1ue68bLrDuGCeJL9EMLHelVIf8u0SUbCseDOvKnoe",
- "//": "user 1 password is 'user1-pwd'",
- "user2": "$2a$10$oym3SYMFXf/9gGfDKKHO4eM1vWNqAZMsRZCL.BORCaP4yp5cdiCXu",
- "//": "user 2 password is 'user2-pwd'"
-}
\ No newline at end of file
diff --git a/restx-core-shell/src/main/resources/templates/srv/main/data/users.json b/restx-core-shell/src/main/resources/templates/srv/main/data/users.json
deleted file mode 100644
index da185be43..000000000
--- a/restx-core-shell/src/main/resources/templates/srv/main/data/users.json
+++ /dev/null
@@ -1,4 +0,0 @@
-[
- {"name":"user1", "roles": []},
- {"name":"user2", "roles": []}
-]
\ No newline at end of file
diff --git a/restx-core-shell/src/main/resources/templates/srv/main/src/main/java/$packagePath$/_AppModule.java b/restx-core-shell/src/main/resources/templates/srv/main/src/main/java/$packagePath$/_AppModule.java
deleted file mode 100644
index 05a215876..000000000
--- a/restx-core-shell/src/main/resources/templates/srv/main/src/main/java/$packagePath$/_AppModule.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package {{mainPackage}};
-
-import restx.config.ConfigLoader;
-import restx.config.ConfigSupplier;
-import restx.factory.Provides;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.base.Charsets;
-import com.google.common.collect.ImmutableSet;
-import restx.security.*;
-import restx.factory.Module;
-import restx.factory.Provides;
-import javax.inject.Named;
-
-import java.nio.file.Paths;
-
-@Module
-public class AppModule {
- @Provides
- public SignatureKey signatureKey() {
- return new SignatureKey("{{signatureKey}}".getBytes(Charsets.UTF_8));
- }
-
- @Provides
- @Named("restx.admin.password")
- public String restxAdminPassword() {
- return "{{adminPassword}}";
- }
-
- @Provides
- public ConfigSupplier appConfigSupplier(ConfigLoader configLoader) {
- // Load settings.properties in {{mainPackage}} package as a set of config entries
- return configLoader.fromResource("{{packagePath}}/settings");
- }
-
- @Provides
- public CredentialsStrategy credentialsStrategy() {
- return new BCryptCredentialsStrategy();
- }
-
- @Provides
- public BasicPrincipalAuthenticator basicPrincipalAuthenticator(
- SecuritySettings securitySettings, CredentialsStrategy credentialsStrategy,
- @Named("restx.admin.passwordHash") String defaultAdminPasswordHash, ObjectMapper mapper) {
- return new StdBasicPrincipalAuthenticator(new StdUserService<>(
- // use file based users repository.
- // Developer's note: prefer another storage mechanism for your users if you need real user management
- // and better perf
- new FileBasedUserRepository<>(
- StdUser.class, // this is the class for the User objects, that you can get in your app code
- // with RestxSession.current().getPrincipal().get()
- // it can be a custom user class, it just need to be json deserializable
- mapper,
-
- // this is the default restx admin, useful to access the restx admin console.
- // if one user with restx-admin role is defined in the repository, this default user won't be
- // available anymore
- new StdUser("admin", ImmutableSet.of("*")),
-
- // the path where users are stored
- Paths.get("data/users.json"),
-
- // the path where credentials are stored. isolating both is a good practice in terms of security
- // it is strongly recommended to follow this approach even if you use your own repository
- Paths.get("data/credentials.json"),
-
- // tells that we want to reload the files dynamically if they are touched.
- // this has a performance impact, if you know your users / credentials never change without a
- // restart you can disable this to get better perfs
- true),
- credentialsStrategy, defaultAdminPasswordHash),
- securitySettings);
- }
-}
diff --git a/restx-core-shell/src/main/resources/templates/srv/main/src/main/java/$packagePath$/_AppServer.java b/restx-core-shell/src/main/resources/templates/srv/main/src/main/java/$packagePath$/_AppServer.java
deleted file mode 100644
index eafaae6b7..000000000
--- a/restx-core-shell/src/main/resources/templates/srv/main/src/main/java/$packagePath$/_AppServer.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package {{mainPackage}};
-
-import com.google.common.base.Optional;
-import restx.server.WebServer;
-import restx.server.Jetty8WebServer;
-
-/**
- * This class can be used to run the app.
- *
- * Alternatively, you can deploy the app as a war in a regular container like tomcat or jetty.
- *
- * Reading the port from system env PORT makes it compatible with heroku.
- */
-public class AppServer {
- public static final String WEB_INF_LOCATION = "src/main/webapp/WEB-INF/web.xml";
- public static final String WEB_APP_LOCATION = "src/main/webapp";
-
- public static void main(String[] args) throws Exception {
- int port = Integer.valueOf(Optional.fromNullable(System.getenv("PORT")).or("{{defaultPort}}"));
- WebServer server = new Jetty8WebServer(WEB_INF_LOCATION, WEB_APP_LOCATION, port, "0.0.0.0");
-
- /*
- * load mode from system property if defined, or default to dev
- * be careful with that setting, if you use this class to launch your server in production, make sure to launch
- * it with -Drestx.mode=prod or change the default here
- */
- System.setProperty("restx.mode", System.getProperty("restx.mode", "dev"));
- System.setProperty("restx.app.package", "{{mainPackage}}");
-
- server.startAndAwait();
- }
-}
diff --git a/restx-core-shell/src/main/resources/templates/srv/main/src/main/resources/$packagePath$/_settings.properties b/restx-core-shell/src/main/resources/templates/srv/main/src/main/resources/$packagePath$/_settings.properties
deleted file mode 100644
index e8734a342..000000000
--- a/restx-core-shell/src/main/resources/templates/srv/main/src/main/resources/$packagePath$/_settings.properties
+++ /dev/null
@@ -1 +0,0 @@
-app.name={{appName}}
\ No newline at end of file
diff --git a/restx-core-shell/src/main/resources/templates/srv/main/src/main/resources/_logback.xml b/restx-core-shell/src/main/resources/templates/srv/main/src/main/resources/_logback.xml
deleted file mode 100644
index 6f5a9402f..000000000
--- a/restx-core-shell/src/main/resources/templates/srv/main/src/main/resources/_logback.xml
+++ /dev/null
@@ -1,94 +0,0 @@
-
-
- true
-
-
-
-
- ${LOGS_FOLDER}/errors.log
-
- ERROR
-
-
- %d [%-16thread] [%-10X{principal}] %-5level %logger{36} - %msg%n
-
-
- ${LOGS_FOLDER}/errors.%d.log
- 30
-
-
-
-
-
-
-
- ${LOGS_FOLDER}/app.log
-
- INFO
-
-
- %d [%-16thread] [%-10X{principal}] %-5level %logger{36} - %msg%n
-
-
- ${LOGS_FOLDER}/app.%d.log
- 10
-
-
-
- ${LOGS_FOLDER}/debug.log
-
- %d [%-16thread] [%-10X{principal}] %-5level %logger{36} - %msg%n
-
-
- ${LOGS_FOLDER}/debug.%i.log.zip
- 1
- 3
-
-
-
- 50MB
-
-
-
-
-
-
-
-
-
-
-
- %d [%-16thread] [%-10X{principal}] %-5level %logger{36} - %msg%n
-
-
-
- ${LOGS_FOLDER}/app.log
-
- %d [%-16thread] [%-10X{principal}] %-5level %logger{36} - %msg%n
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/restx-core-shell/src/main/resources/templates/srv/main/src/main/webapp/WEB-INF/_web.xml b/restx-core-shell/src/main/resources/templates/srv/main/src/main/webapp/WEB-INF/_web.xml
deleted file mode 100644
index ffb23f8f8..000000000
--- a/restx-core-shell/src/main/resources/templates/srv/main/src/main/webapp/WEB-INF/_web.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
- restx
- restx.servlet.RestxMainRouterServlet
- 1
-
-
- restx
- {{baseAPIPath}}/*
-
-
diff --git a/restx-core-shell/src/test/java/restx/core/shell/NewAppTest.java b/restx-core-shell/src/test/java/restx/core/shell/NewAppTest.java
deleted file mode 100644
index d473402fd..000000000
--- a/restx-core-shell/src/test/java/restx/core/shell/NewAppTest.java
+++ /dev/null
@@ -1,138 +0,0 @@
-package restx.core.shell;
-
-import jline.console.ConsoleReader;
-import org.apache.maven.it.VerificationException;
-import org.apache.maven.it.Verifier;
-import org.junit.*;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import restx.CoreModule;
-import restx.build.RestxJsonSupport;
-import restx.common.OSUtils;
-import restx.factory.Factory;
-import restx.shell.RestxShell;
-
-import java.io.*;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Arrays;
-import java.util.List;
-
-import static org.mockito.Mockito.*;
-
-/**
- * @author fcamblor
- */
-@RunWith(Parameterized.class)
-public class NewAppTest {
-
- @Rule
- public TemporaryFolder workDirectory = new TemporaryFolder();
-
- private final AppShellCommand.NewAppDescriptor descriptor;
- private String initialRestxShellHomeValue;
-
- @Before
- public void setup() throws IOException {
- // Avoiding "restx.shell.home_IS_UNDEFINED/ dir due to logs
- this.initialRestxShellHomeValue = System.getProperty("restx.shell.home");
- if(this.initialRestxShellHomeValue == null) {
- System.setProperty("restx.shell.home", workDirectory.newFolder(".restx").getAbsolutePath());
- }
- }
-
- @After
- public void teardown() {
- if(this.initialRestxShellHomeValue == null) {
- System.getProperties().remove("restx.shell.home");
- }
- }
-
- @Parameterized.Parameters(name="{0}")
- public static Iterable]