Search in sources :

Example 1 with Object

use of com.ibm.uma.om.Object in project openj9 by eclipse.

the class ObjectParser method parse.

public static Object parse(Node node, String containingFile) throws UMAException {
    NamedNodeMap attributes = node.getAttributes();
    NodeList nodeList = node.getChildNodes();
    String nodeName = node.getNodeName();
    IPlatform platform = UMA.getUma().getPlatform();
    int objectType = Object.GROUP;
    if (nodeName.equalsIgnoreCase("object")) {
        objectType = Object.SINGLE;
    }
    String name = attributes.getNamedItem("name").getNodeValue();
    if (objectType == Object.SINGLE) {
        if (name.split("\\.").length == 1) {
            name = name + platform.getObjectExtension();
        }
    }
    Object object = new Object(name, containingFile);
    object.setType(objectType);
    Parser.populatePredicateList(nodeList, object);
    return object;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) IPlatform(com.ibm.uma.IPlatform) Object(com.ibm.uma.om.Object)

Example 2 with Object

use of com.ibm.uma.om.Object in project openj9 by eclipse.

the class ObjectsParser method parse.

public static Objects parse(Node node, String containingFile) throws UMAException {
    Objects objects = new Objects(containingFile);
    NamedNodeMap attributes = node.getAttributes();
    objects.setGroup(attributes.getNamedItem("group").getNodeValue());
    NodeList nodeList = node.getChildNodes();
    for (int j = 0; j < nodeList.getLength(); j++) {
        Node item = nodeList.item(j);
        if (item.getNodeName().equalsIgnoreCase("object")) {
            Object object = ObjectParser.parse(item, containingFile);
            objects.addObject(object);
        } else if (item.getNodeName().equalsIgnoreCase("group")) {
            NamedNodeMap attr = item.getAttributes();
            String objectGroupName = attr.getNamedItem("name").getNodeValue();
            Object object = new Object(objectGroupName, containingFile);
            objects.addObject(object);
        }
    }
    Parser.populatePredicateList(nodeList, objects);
    return objects;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Objects(com.ibm.uma.om.Objects) Object(com.ibm.uma.om.Object)

Example 3 with Object

use of com.ibm.uma.om.Object in project openj9 by eclipse.

the class UMA method writeMakefileObjectLine.

void writeMakefileObjectLine(StringBuffer buffer, Module module, Artifact artifact) throws UMAException {
    // Add all objects into a set, eliminating duplicates.
    HashSet<String> objtable = new HashSet<String>();
    Vector<Object> objects = artifact.getObjects();
    for (Object object : objects) {
        if (object.evaluate()) {
            switch(object.getType()) {
                case Object.SINGLE:
                    if (!objtable.contains(object.getName())) {
                        objtable.add(object.getName());
                    }
                    break;
                case Object.GROUP:
                    Vector<String> newGroups = new Vector<String>();
                    newGroups.add(object.getName());
                    while (newGroups != null) {
                        Vector<String> groups = newGroups;
                        newGroups = null;
                        for (String groupName : groups) {
                            Objects objs = module.getObjects().get(groupName);
                            if (objs == null) {
                                throw new UMAException("Error: bad object group name [" + groupName + "] in " + module.getModulePath() + ".");
                            }
                            if (objs.evaluate()) {
                                for (Object obj : objs.getObjects()) {
                                    if (obj.evaluate()) {
                                        switch(obj.getType()) {
                                            case Object.SINGLE:
                                                if (!objtable.contains(obj.getName())) {
                                                    objtable.add(obj.getName());
                                                }
                                                break;
                                            case Object.GROUP:
                                                if (newGroups == null) {
                                                    newGroups = new Vector<String>();
                                                }
                                                newGroups.add(obj.getName());
                                                break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
            }
        // switch
        }
    }
    StringBuffer objectBuffer = new StringBuffer();
    if (objtable.size() >= 1) {
        produceObjectLine(objectBuffer, objtable, "UMA_OBJECTS");
    }
    HashSet<String> targetSpecificObjects = new HashSet<String>();
    produceObjectLine(objectBuffer, targetSpecificObjects, "UMA_OBJECTS+");
    objtable = new HashSet<String>();
    platform.addTargetSpecificObjectsForStaticLink(objtable, artifact);
    if (objtable.size() >= 1) {
        produceObjectLine(objectBuffer, objtable, "UMA_STATIC_OBJECTS");
    }
    if (objectBuffer.length() > 0) {
        buffer.append(objectBuffer.toString());
    }
}
Also used : Objects(com.ibm.uma.om.Objects) Object(com.ibm.uma.om.Object) Vector(java.util.Vector) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 4 with Object

use of com.ibm.uma.om.Object in project openj9 by eclipse.

the class ArtifactParser method parse.

public static Artifact parse(Node artifactNode, Module module) throws UMAException {
    Artifact artifact = new Artifact(module);
    NodeList nodeList = artifactNode.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        String nodeName = node.getLocalName();
        if (nodeName == null)
            continue;
        if (nodeName.equalsIgnoreCase("description")) {
            NodeList descChildren = node.getChildNodes();
            Node descChild = descChildren.item(0);
            artifact.setDescription(descChild.getNodeValue());
        } else if (nodeName.equalsIgnoreCase("options")) {
            NodeList optionsNodeList = node.getChildNodes();
            for (int j = 0; j < optionsNodeList.getLength(); j++) {
                Node optionItem = optionsNodeList.item(j);
                NamedNodeMap attributes = optionItem.getAttributes();
                if (attributes == null)
                    continue;
                Option option = OptionParser.parse(optionItem, artifact.getContainingFile());
                artifact.addOption(option);
            }
        } else if (nodeName.equalsIgnoreCase("phase")) {
            NodeList phaseChildren = node.getChildNodes();
            for (int j = 0; j < phaseChildren.getLength(); j++) {
                Node phasesNode = phaseChildren.item(j);
                String phaselist = phasesNode.getNodeValue();
                String[] phases = phaselist.split("\\s");
                for (int k = 0; k < phases.length; k++) {
                    try {
                        artifact.setPhase(UMA.getUma().getConfiguration().phaseFromString(phases[k]), true);
                    } catch (UMABadPhaseNameException e) {
                        throw new UMAException("in file: " + artifact.getContainingFile(), e);
                    }
                }
            }
        } else if (nodeName.equalsIgnoreCase("includes")) {
            NodeList includesNodeList = node.getChildNodes();
            for (int j = 0; j < includesNodeList.getLength(); j++) {
                Node includeItem = includesNodeList.item(j);
                NamedNodeMap attributes = includeItem.getAttributes();
                if (attributes == null)
                    continue;
                Include include = new Include(artifact.getContainingFile());
                include.setPath(attributes.getNamedItem("path").getNodeValue());
                include.setType(attributes.getNamedItem("type").getNodeValue());
                artifact.addInclude(include);
                Parser.populatePredicateList(includeItem.getChildNodes(), include);
            }
        } else if (nodeName.equalsIgnoreCase("commands")) {
            NodeList commandsNodeList = node.getChildNodes();
            for (int j = 0; j < commandsNodeList.getLength(); j++) {
                Node commandItem = commandsNodeList.item(j);
                NamedNodeMap attributes = commandItem.getAttributes();
                if (attributes == null)
                    continue;
                Command command = new Command(artifact.getContainingFile());
                command.setCommand(attributes.getNamedItem("line").getNodeValue());
                command.setType(attributes.getNamedItem("type").getNodeValue());
                artifact.addCommand(command);
                Parser.populatePredicateList(commandItem.getChildNodes(), command);
            }
        } else if (nodeName.equalsIgnoreCase("dependencies")) {
            NodeList dependenciesNodeList = node.getChildNodes();
            for (int j = 0; j < dependenciesNodeList.getLength(); j++) {
                Node dependencyItem = dependenciesNodeList.item(j);
                NamedNodeMap attributes = dependencyItem.getAttributes();
                if (attributes == null)
                    continue;
                Dependency dependency = new Dependency(artifact.getContainingFile());
                dependency.setDependency(attributes.getNamedItem("name").getNodeValue());
                artifact.addDependency(dependency);
                Parser.populatePredicateList(dependencyItem.getChildNodes(), dependency);
            }
        } else if (nodeName.equalsIgnoreCase("libraries")) {
            NodeList linkNodeList = node.getChildNodes();
            for (int j = 0; j < linkNodeList.getLength(); j++) {
                Node linkItem = linkNodeList.item(j);
                if (linkItem.getNodeName().equalsIgnoreCase("library")) {
                    Library library = LibraryParser.parse(linkItem, artifact.getContainingFile());
                    artifact.addLibrary(library);
                }
            }
        } else if (nodeName.equalsIgnoreCase("static-link-libraries")) {
            NodeList linkNodeList = node.getChildNodes();
            for (int j = 0; j < linkNodeList.getLength(); j++) {
                Node linkItem = linkNodeList.item(j);
                if (linkItem.getNodeName().equalsIgnoreCase("library")) {
                    Library library = LibraryParser.parse(linkItem, artifact.getContainingFile());
                    artifact.addStaticLinkLibrary(library);
                }
            }
        } else if (nodeName.equalsIgnoreCase("objects")) {
            NodeList linkNodeList = node.getChildNodes();
            for (int j = 0; j < linkNodeList.getLength(); j++) {
                Node linkItem = linkNodeList.item(j);
                if (linkItem.getNodeName().equalsIgnoreCase("group") || linkItem.getNodeName().equalsIgnoreCase("object")) {
                    Object object = ObjectParser.parse(linkNodeList.item(j), artifact.getContainingFile());
                    artifact.addObject(object);
                }
            }
        } else if (nodeName.equalsIgnoreCase("vpaths")) {
            NodeList vpathsNodeList = node.getChildNodes();
            for (int j = 0; j < vpathsNodeList.getLength(); j++) {
                Node vpathItem = vpathsNodeList.item(j);
                if (vpathItem.getNodeName().equalsIgnoreCase("vpath")) {
                    VPath vpath = VPathParser.parse(vpathItem, artifact.getContainingFile());
                    artifact.addVPath(vpath);
                }
            }
        } else if (nodeName.equalsIgnoreCase("makefilestubs")) {
            NodeList mfsNodeList = node.getChildNodes();
            for (int j = 0; j < mfsNodeList.getLength(); j++) {
                Node mfsItem = mfsNodeList.item(j);
                if (mfsItem.getNodeName().equalsIgnoreCase("makefilestub")) {
                    NamedNodeMap attributes = mfsItem.getAttributes();
                    Node dataNode = attributes.getNamedItem("data");
                    MakefileStub makefileStub = new MakefileStub(dataNode.getNodeValue(), artifact.getContainingFile());
                    artifact.addMakefileStub(makefileStub);
                    Parser.populatePredicateList(mfsItem.getChildNodes(), makefileStub);
                }
            }
        } else if (nodeName.equalsIgnoreCase("exports")) {
            NodeList exportsNodeList = node.getChildNodes();
            for (int j = 0; j < exportsNodeList.getLength(); j++) {
                Node exportNode = exportsNodeList.item(j);
                if (exportNode.getNodeName().equalsIgnoreCase("group")) {
                    Export group = ExportParser.parse(exportNode, artifact.getContainingFile());
                    artifact.addExport(group);
                    group.setType(Export.TYPE_GROUP);
                } else if (exportNode.getNodeName().equalsIgnoreCase("export")) {
                    Export group = ExportParser.parse(exportNode, artifact.getContainingFile());
                    artifact.addExport(group);
                    group.setType(Export.TYPE_FUNCTION);
                }
            }
        } else if (nodeName.equalsIgnoreCase("flags")) {
            NodeList flagsNodeList = node.getChildNodes();
            for (int j = 0; j < flagsNodeList.getLength(); j++) {
                Node item = flagsNodeList.item(j);
                Flag f = FlagParser.parse(item, artifact.getContainingFile());
                if (f != null) {
                    artifact.addFlag(f);
                }
            }
        }
    }
    NamedNodeMap attributes = artifactNode.getAttributes();
    Node nameNode = attributes.getNamedItem("name");
    artifact.setName(nameNode.getNodeValue());
    Node typeNode = attributes.getNamedItem("type");
    artifact.setType(typeNode.getNodeValue());
    Node bundleNode = attributes.getNamedItem("bundle");
    if (bundleNode != null) {
        artifact.setBundle(bundleNode.getNodeValue());
    }
    Node scopeNode = attributes.getNamedItem("scope");
    if (scopeNode != null) {
        artifact.setScope(scopeNode.getNodeValue());
    }
    Node includeInAllTargetNode = attributes.getNamedItem("all");
    if (includeInAllTargetNode.getNodeValue().equalsIgnoreCase("true")) {
        artifact.setIncludeInAllTarget(true);
    } else {
        artifact.setIncludeInAllTarget(false);
    }
    Node loadgroupNode = attributes.getNamedItem("loadgroup");
    if (loadgroupNode != null) {
        artifact.setLoadgroup(loadgroupNode.getNodeValue());
    }
    Node buildLocal = attributes.getNamedItem("buildlocal");
    if (buildLocal.getNodeValue().equalsIgnoreCase("true")) {
        artifact.setBuildLocal(true);
    }
    Node appendReleaseNode = attributes.getNamedItem("appendrelease");
    if (appendReleaseNode.getNodeValue().equalsIgnoreCase("true")) {
        artifact.setAppendRelease(true);
    }
    Node consoleNode = attributes.getNamedItem("console");
    if (consoleNode.getNodeValue().equalsIgnoreCase("false")) {
        artifact.setConsoleApplication(false);
    } else {
        artifact.setConsoleApplication(true);
    }
    Parser.populatePredicateList(nodeList, artifact);
    return artifact;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) MakefileStub(com.ibm.uma.om.MakefileStub) Include(com.ibm.uma.om.Include) UMAException(com.ibm.uma.UMAException) Dependency(com.ibm.uma.om.Dependency) Flag(com.ibm.uma.om.Flag) Artifact(com.ibm.uma.om.Artifact) Command(com.ibm.uma.om.Command) Export(com.ibm.uma.om.Export) Option(com.ibm.uma.om.Option) Object(com.ibm.uma.om.Object) VPath(com.ibm.uma.om.VPath) Library(com.ibm.uma.om.Library) UMABadPhaseNameException(com.ibm.uma.UMABadPhaseNameException)

Aggregations

Object (com.ibm.uma.om.Object)4 NamedNodeMap (org.w3c.dom.NamedNodeMap)3 NodeList (org.w3c.dom.NodeList)3 Objects (com.ibm.uma.om.Objects)2 Node (org.w3c.dom.Node)2 IPlatform (com.ibm.uma.IPlatform)1 UMABadPhaseNameException (com.ibm.uma.UMABadPhaseNameException)1 UMAException (com.ibm.uma.UMAException)1 Artifact (com.ibm.uma.om.Artifact)1 Command (com.ibm.uma.om.Command)1 Dependency (com.ibm.uma.om.Dependency)1 Export (com.ibm.uma.om.Export)1 Flag (com.ibm.uma.om.Flag)1 Include (com.ibm.uma.om.Include)1 Library (com.ibm.uma.om.Library)1 MakefileStub (com.ibm.uma.om.MakefileStub)1 Option (com.ibm.uma.om.Option)1 VPath (com.ibm.uma.om.VPath)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1