Package restx.build.org.json

Examples of restx.build.org.json.JSONObject


* Time: 2:08 PM
*/
public class MavenSupport implements RestxBuild.Parser, RestxBuild.Generator {
    static class Parser {
        public ModuleDescriptor parse(InputStream stream) throws IOException {
            JSONObject jsonObject = XML.toJSONObject(RestxBuildHelper.toString(stream)).getJSONObject("project");

            GAV parent;
            if (jsonObject.has("parent")) {
                JSONObject parentObject = jsonObject.getJSONObject("parent");
                parent = getGav(parentObject);
            } else {
                parent = null;
            }
            GAV gav = getGav(jsonObject);
            String packaging = jsonObject.has("packaging") ? jsonObject.getString("packaging") : "jar";

            Map<String, String> properties = new LinkedHashMap<>();
            if (jsonObject.has("properties")) {
                JSONObject props = jsonObject.getJSONObject("properties");
                for (Object o : props.keySet()) {
                    String p = (String) o;

                    if (p.equals("maven.compiler.target") || p.equals("maven.compiler.source")) {
                        properties.put("java.version", String.valueOf(props.get(p)));
                    } else {
                        properties.put(p, String.valueOf(props.get(p)));
                    }
                }
            }

            Map<String, List<ModuleDependency>> dependencies = new LinkedHashMap<>();

            if (jsonObject.has("dependencies")) {
                JSONArray deps = jsonObject.getJSONObject("dependencies").getJSONArray("dependency");

                for (int i = 0; i < deps.length(); i++) {
                    JSONObject dep = deps.getJSONObject(i);
                    String scope = dep.has("scope") ? dep.getString("scope") : "compile";

                    List<ModuleDependency> scopeDependencies = dependencies.get(scope);
                    if (scopeDependencies == null) {
                        dependencies.put(scope, scopeDependencies = new ArrayList<>());
                    }
View Full Code Here


        }
        public ModuleDescriptor parse(InputStream inputStream) throws IOException {
            return parse(null, inputStream);
        }
        private ModuleDescriptor parse(Path path, InputStream inputStream) throws IOException {
            JSONObject jsonObject = new JSONObject(new JSONTokener(new InputStreamReader(inputStream, "UTF-8")));

            Map<String, String> properties = new LinkedHashMap<>();
            if (jsonObject.has("properties")) {
                loadJsonProperties(path == null ? null : path.getParent(), properties, jsonObject.getJSONObject("properties"));
            }

            GAV parent = null;
            if (jsonObject.has("parent")) {
                parent = GAV.parse(expandProperties(properties, jsonObject.getString("parent")));
            }
            GAV gav = GAV.parse(expandProperties(properties, jsonObject.getString("module")));

            String packaging = jsonObject.has("packaging") ? jsonObject.getString("packaging") : "jar";

            Map<String, List<ModuleDependency>> dependencies = new LinkedHashMap<>();
            if (jsonObject.has("dependencies")) {
                JSONObject scopes = jsonObject.getJSONObject("dependencies");
                for (Object s : scopes.keySet()) {
                    String scope = s.toString();
                    List<ModuleDependency> scopeDeps = new ArrayList<>();
                    dependencies.put(scope, scopeDeps);

                    JSONArray deps = scopes.getJSONArray(scope);
                    for (int i = 0; i < deps.length(); i++) {
                        scopeDeps.add(new ModuleDependency(GAV.parse(deps.getString(i))));
                    }
                }
            }

            Map<String, List<ModuleFragment>> fragments = new LinkedHashMap<>();
            if (jsonObject.has("fragments")) {
                JSONObject jsonFragments = jsonObject.getJSONObject("fragments");
                for (Object key : jsonFragments.keySet()) {
                    String type = (String) key;
                    List<ModuleFragment> fragmentsForType = new ArrayList<>();

                    JSONArray array = jsonFragments.getJSONArray(type);
                    for (int i = 0; i < array.length(); i++) {
                        String url = expandProperties(properties, array.getString(i));

                        if (url.startsWith("classpath://")) {
                            String fragmentPath = url.substring("classpath://".length());
View Full Code Here

                                                    "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));
                }
View Full Code Here

TOP

Related Classes of restx.build.org.json.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.