Path: blob/master/sourcetools/com.ibm.uma/com/ibm/uma/om/parser/ArtifactParser.java
6005 views
/*******************************************************************************1* Copyright (c) 2001, 2017 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/21package com.ibm.uma.om.parser;2223import org.w3c.dom.NamedNodeMap;24import org.w3c.dom.Node;25import org.w3c.dom.NodeList;2627import com.ibm.uma.UMA;28import com.ibm.uma.UMABadPhaseNameException;29import com.ibm.uma.UMAException;30import com.ibm.uma.om.Artifact;31import com.ibm.uma.om.Command;32import com.ibm.uma.om.Dependency;33import com.ibm.uma.om.Export;34import com.ibm.uma.om.Flag;35import com.ibm.uma.om.Include;36import com.ibm.uma.om.Library;37import com.ibm.uma.om.MakefileStub;38import com.ibm.uma.om.Module;39import com.ibm.uma.om.Object;40import com.ibm.uma.om.Option;41import com.ibm.uma.om.VPath;4243public class ArtifactParser {44static public Artifact parse(Node artifactNode, Module module) throws UMAException {45Artifact artifact = new Artifact(module);4647NodeList nodeList = artifactNode.getChildNodes();48for (int i = 0; i < nodeList.getLength(); i++) {49Node node = nodeList.item(i);50String nodeName = node.getLocalName();51if ( nodeName == null ) continue;52if ( nodeName.equalsIgnoreCase("description")) {53NodeList descChildren = node.getChildNodes();54Node descChild = descChildren.item(0);55artifact.setDescription(descChild.getNodeValue());56} else if ( nodeName.equalsIgnoreCase("options") ) {57NodeList optionsNodeList = node.getChildNodes();58for ( int j=0; j<optionsNodeList.getLength(); j++ ) {59Node optionItem = optionsNodeList.item(j);60NamedNodeMap attributes = optionItem.getAttributes();61if (attributes == null) continue;62Option option = OptionParser.parse(optionItem, artifact.getContainingFile());63artifact.addOption(option);64}65} else if ( nodeName.equalsIgnoreCase("phase")) {66NodeList phaseChildren = node.getChildNodes();67for (int j=0; j<phaseChildren.getLength(); j++) {68Node phasesNode = phaseChildren.item(j);69String phaselist = phasesNode.getNodeValue();70String[] phases = phaselist.split("\\s");71for ( int k=0; k<phases.length; k++ ) {72try {73artifact.setPhase(UMA.getUma().getConfiguration().phaseFromString(phases[k]), true);74} catch (UMABadPhaseNameException e) {75throw new UMAException("in file: " + artifact.getContainingFile(), e);76}77}78}79} else if ( nodeName.equalsIgnoreCase("includes") ) {80NodeList includesNodeList = node.getChildNodes();81for ( int j=0; j<includesNodeList.getLength(); j++ ) {82Node includeItem = includesNodeList.item(j);83NamedNodeMap attributes = includeItem.getAttributes();84if (attributes == null) continue;85Include include = new Include(artifact.getContainingFile());86include.setPath(attributes.getNamedItem("path").getNodeValue());87include.setType(attributes.getNamedItem("type").getNodeValue());88artifact.addInclude(include);89Parser.populatePredicateList(includeItem.getChildNodes(), include);90}91} else if ( nodeName.equalsIgnoreCase("commands") ) {92NodeList commandsNodeList = node.getChildNodes();93for ( int j=0; j<commandsNodeList.getLength(); j++ ) {94Node commandItem = commandsNodeList.item(j);95NamedNodeMap attributes = commandItem.getAttributes();96if (attributes == null) continue;97Command command = new Command(artifact.getContainingFile());98command.setCommand(attributes.getNamedItem("line").getNodeValue());99command.setType(attributes.getNamedItem("type").getNodeValue());100artifact.addCommand(command);101Parser.populatePredicateList(commandItem.getChildNodes(), command);102}103} else if ( nodeName.equalsIgnoreCase("dependencies") ) {104NodeList dependenciesNodeList = node.getChildNodes();105for ( int j=0; j<dependenciesNodeList.getLength(); j++ ) {106Node dependencyItem = dependenciesNodeList.item(j);107NamedNodeMap attributes = dependencyItem.getAttributes();108if (attributes == null) continue;109Dependency dependency = new Dependency(artifact.getContainingFile());110dependency.setDependency(attributes.getNamedItem("name").getNodeValue());111artifact.addDependency(dependency);112Parser.populatePredicateList(dependencyItem.getChildNodes(), dependency);113}114} else if ( nodeName.equalsIgnoreCase("libraries") ) {115NodeList linkNodeList = node.getChildNodes();116for ( int j=0; j<linkNodeList.getLength(); j++ ) {117Node linkItem = linkNodeList.item(j);118if ( linkItem.getNodeName().equalsIgnoreCase("library") ) {119Library library = LibraryParser.parse(linkItem, artifact.getContainingFile());120artifact.addLibrary(library);121}122}123} else if ( nodeName.equalsIgnoreCase("static-link-libraries") ) {124NodeList linkNodeList = node.getChildNodes();125for ( int j=0; j<linkNodeList.getLength(); j++ ) {126Node linkItem = linkNodeList.item(j);127if ( linkItem.getNodeName().equalsIgnoreCase("library") ) {128Library library = LibraryParser.parse(linkItem, artifact.getContainingFile());129artifact.addStaticLinkLibrary(library);130}131}132} else if ( nodeName.equalsIgnoreCase("objects") ) {133NodeList linkNodeList = node.getChildNodes();134for ( int j=0; j<linkNodeList.getLength(); j++ ) {135Node linkItem = linkNodeList.item(j);136if ( linkItem.getNodeName().equalsIgnoreCase("group") ||137linkItem.getNodeName().equalsIgnoreCase("object") ) {138Object object = ObjectParser.parse(linkNodeList.item(j), artifact.getContainingFile());139artifact.addObject(object);140}141}142} else if ( nodeName.equalsIgnoreCase("vpaths") ) {143NodeList vpathsNodeList = node.getChildNodes();144for ( int j=0; j<vpathsNodeList.getLength(); j++ ) {145Node vpathItem = vpathsNodeList.item(j);146if ( vpathItem.getNodeName().equalsIgnoreCase("vpath") ) {147VPath vpath = VPathParser.parse(vpathItem, artifact.getContainingFile());148artifact.addVPath(vpath);149}150}151} else if ( nodeName.equalsIgnoreCase("makefilestubs") ) {152NodeList mfsNodeList = node.getChildNodes();153for ( int j=0;j<mfsNodeList.getLength(); j++ ) {154Node mfsItem = mfsNodeList.item(j);155if ( mfsItem.getNodeName().equalsIgnoreCase("makefilestub") ) {156NamedNodeMap attributes = mfsItem.getAttributes();157Node dataNode = attributes.getNamedItem("data");158MakefileStub makefileStub = new MakefileStub(dataNode.getNodeValue(), artifact.getContainingFile());159artifact.addMakefileStub(makefileStub);160Parser.populatePredicateList(mfsItem.getChildNodes(), makefileStub);161}162}163} else if ( nodeName.equalsIgnoreCase("exports") ) {164NodeList exportsNodeList = node.getChildNodes();165for ( int j=0; j<exportsNodeList.getLength(); j++ ) {166Node exportNode = exportsNodeList.item(j);167if ( exportNode.getNodeName().equalsIgnoreCase("group") ) {168Export group = ExportParser.parse(exportNode, artifact.getContainingFile());169artifact.addExport(group);170group.setType(Export.TYPE_GROUP);171} else if ( exportNode.getNodeName().equalsIgnoreCase("export") ) {172Export group = ExportParser.parse(exportNode, artifact.getContainingFile());173artifact.addExport(group);174group.setType(Export.TYPE_FUNCTION);175}176}177} else if (nodeName.equalsIgnoreCase("flags") ) {178NodeList flagsNodeList = node.getChildNodes();179for ( int j=0; j<flagsNodeList.getLength(); j++ ) {180Node item = flagsNodeList.item(j);181Flag f = FlagParser.parse(item, artifact.getContainingFile());182if (f != null) {183artifact.addFlag(f);184}185}186}187}188189NamedNodeMap attributes = artifactNode.getAttributes();190191Node nameNode = attributes.getNamedItem("name");192artifact.setName(nameNode.getNodeValue());193194Node typeNode = attributes.getNamedItem("type");195artifact.setType(typeNode.getNodeValue());196197Node bundleNode = attributes.getNamedItem("bundle");198if ( bundleNode != null ) {199artifact.setBundle(bundleNode.getNodeValue());200}201202Node scopeNode = attributes.getNamedItem("scope");203if ( scopeNode != null ) {204artifact.setScope(scopeNode.getNodeValue());205}206207Node includeInAllTargetNode = attributes.getNamedItem("all");208if ( includeInAllTargetNode.getNodeValue().equalsIgnoreCase("true") ) {209artifact.setIncludeInAllTarget(true);210} else {211artifact.setIncludeInAllTarget(false);212}213214Node loadgroupNode = attributes.getNamedItem("loadgroup");215if ( loadgroupNode != null ) {216artifact.setLoadgroup(loadgroupNode.getNodeValue());217}218219Node buildLocal = attributes.getNamedItem("buildlocal");220if ( buildLocal.getNodeValue().equalsIgnoreCase("true") ) {221artifact.setBuildLocal(true);222}223224Node appendReleaseNode = attributes.getNamedItem("appendrelease");225if ( appendReleaseNode.getNodeValue().equalsIgnoreCase("true") ) {226artifact.setAppendRelease(true);227}228229Node consoleNode = attributes.getNamedItem("console");230if ( consoleNode.getNodeValue().equalsIgnoreCase("false") ) {231artifact.setConsoleApplication(false);232} else {233artifact.setConsoleApplication(true);234}235236Parser.populatePredicateList(nodeList, artifact);237238return artifact;239}240241242}243244245