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