Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/sourcetools/com.ibm.jpp.preprocessor/com/ibm/jpp/om/ConfigXMLHandler.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 1999, 2020 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.jpp.om;
23
24
import java.io.File;
25
import java.io.FileInputStream;
26
import java.io.FileNotFoundException;
27
import java.io.IOException;
28
import java.util.ArrayList;
29
import java.util.HashMap;
30
import java.util.Iterator;
31
import java.util.List;
32
import java.util.Map;
33
import java.util.StringTokenizer;
34
35
import com.ibm.jpp.xml.IXMLDocumentHandler;
36
import com.ibm.jpp.xml.XMLException;
37
import com.ibm.jpp.xml.XMLParser;
38
39
/**
40
* <b>HOW TO USE XML TO SETUP CONFIGURATION AND PREPROCESS JOBS </b>
41
* <p>
42
* XMl files are used two different ways in the preprocessor
43
*
44
* <ol>
45
* <li>The default set of configurations is loaded when the preprocessing
46
* begins, loading in a number of configurations/sets from default.xml which
47
* must be in the plugin dir (if using the plugin) or the same location as the
48
* preprocess code is located. (Use the command line argument "-xmldefault
49
* {xmlfilepath}" to define a different default filepath</li>
50
* <li>A second xml file can be defined using the command line argument (-xml
51
* {xmlfilepath} {basedirectory}). With this command, the given xml file is
52
* parsed for not only configuration setup, but relative source and output paths
53
* for the build. The only other command line arguments currently allowed in
54
* combination with -xml is -xmldefault. All build information
55
* must be found inside the xml. More than one configuration to be built can be
56
* defined in the xml and configurations missing source or output dirs will be
57
* ignored.</li>
58
* </ol>
59
*
60
* <p>For more details of the command structure see CommandLineBuilder.java
61
* <p>
62
* <b>FUNCTIONALITY IN DEFAULT XML FILES FOR LOADING CONFIGURATIONS </b>
63
* <p>
64
* See the default.xml or the plugin's plugin.xml for examples
65
* <ol>
66
* <li>"set" and "configuration" elements must define the attribute label.
67
* </li>
68
* <li>Only configurations can have source/output elements</li>
69
* <li>A non-unique set/config label may result in dependency problems (-xml
70
* will override -xmldefault, but try to not have anything dependent on that
71
* set/config)</li>
72
* <li>flags attribute used to add individual flags, dependencies attr used to
73
* add all of the flags in that set/config (therefore the dependency set/config
74
* must be defined in -xml or -defaultxml</li>
75
* <li>Precede the flag/dependency name with '-' to remove, rather than add
76
* that flag/dependency from the final flagset, trying it remove flags that
77
* don't exist in the flagset will not cause an error.</li>
78
* <li>Options that apply to the entire set/config are added as a separate
79
* element called parameter, with attributes name and value.</li>
80
* <li>Other elements, such as extension point will be ignored</li>
81
* <li>Use the output path attribute of configuration to set the output path,
82
* note that this path will be combined with the {basedir} arg</li>
83
* <li>For each source, create a separate source element, with attribute path
84
* to define the source location. Add "type=simplecopy" to do a copy instead of
85
* a preprocess, add an element called parameter with attributes name and value
86
* to add an option to a specific source dir</li>
87
* </ol>
88
*
89
* <pre>
90
* EX:
91
* &lt;set
92
* label="xtr"
93
* flags="xJava,xIO,xThread,xNet,Deprecated,MAX13"&gt;
94
* &lt;/set&gt;
95
*
96
* EX:
97
* &lt;configuration
98
* label="XTREME"
99
* outputpath="pConfig XTREME/src"
100
* dependencies="xtr"&gt;
101
* &lt;source path="src"&gt;
102
* &lt;parameter name="macro:define" value="com.ibm.oti.vm.library.version=29;com.ibm.oti.jcl.build=plugin2"/&gt;
103
* &lt;/source&gt;
104
* &lt;parameter name="jxerules:outputdir" value="com/ibm/oti/util"/&gt;
105
* &lt;/configuration&gt;
106
* </pre>
107
*/
108
public class ConfigXMLHandler implements IXMLDocumentHandler {
109
110
private static final int MAJOR_VERSION = 3;
111
112
private final List<ConfigObject> configObjects;
113
private final List<ConfigObject> requiredObjects;
114
private ConfigObject currentConfig;
115
private final FileInputStream XMLInput;
116
117
private int configVersion;
118
private String baseDir;
119
private String srcRoot;
120
private Src currentSource;
121
private boolean inSource = false;
122
private boolean inGlobals = false;
123
private boolean inAutomatedTests = false;
124
private String testsProject = "";
125
private final List<ClassPathEntry> testsClassPaths;
126
private final List<Src> testsSources;
127
private final List<ClassPathEntry> classPaths;
128
private final Map<String, String> defaultTestsResources;
129
/* [PR 119756] config project prefix and postfix support in jpp_configuration.xml file */
130
private String outputPathPrefix = "";
131
private String outputPathSuffix = "";
132
private String testsOutputPathPrefix = "";
133
private String testsOutputPathSuffix = " Tests";
134
private String bootTestsOutputPathPrefix = "";
135
private String bootTestsOutputPathSuffix = " Tests BootPath";
136
137
/**
138
* Constructs a ConfigXMLHandler...
139
*
140
* @param filename the file to be parsed
141
*
142
* @throws FileNotFoundException if the file cannot be located
143
*/
144
public ConfigXMLHandler(String filename) throws FileNotFoundException {
145
this.XMLInput = new FileInputStream(filename);
146
srcRoot = "";
147
configObjects = new ArrayList<>();
148
requiredObjects = new ArrayList<>();
149
testsClassPaths = new ArrayList<>();
150
classPaths = new ArrayList<>();
151
testsSources = new ArrayList<>();
152
defaultTestsResources = new HashMap<>();
153
}
154
155
public int getConfigVersion() {
156
return configVersion;
157
}
158
159
/**
160
* @param baseDir the base directory
161
*/
162
public void setBaseDir(String baseDir) {
163
this.baseDir = baseDir;
164
}
165
166
/**
167
* @param srcRoot the source root path
168
*/
169
public void setSourceRoot(String srcRoot) {
170
this.srcRoot = srcRoot;
171
}
172
173
/**
174
* Returns only the configurations from the required XMLs. This is the opposite of
175
* {@link #getLocalConfigs()}.
176
*
177
* @return only the configurations from required XMLs
178
*/
179
public List<ConfigObject> getRequiredConfigs() {
180
return requiredObjects;
181
}
182
183
/**
184
* Returns only the configurations defined in the parent XML (and not in
185
* the requires XMLs).
186
*
187
* @return only the configurations defined in the parent XML
188
*/
189
public List<ConfigObject> getLocalConfigs() {
190
return configObjects;
191
}
192
193
/**
194
* Returns all of the configurations. This combines local and requires configs.
195
*
196
* @return all of the configurations
197
*
198
* @see #getLocalConfigs()
199
* @see #getRequiredConfigs()
200
*/
201
public List<ConfigObject> getAllConfigs() {
202
List<ConfigObject> temp = new ArrayList<>(requiredObjects);
203
temp.addAll(configObjects);
204
return temp;
205
}
206
207
/**
208
* Returns the name of the automated tests project.
209
*
210
* @return the name of the automated tests project
211
*/
212
public String getTestsProject() {
213
return testsProject;
214
}
215
216
/**
217
* Returns outputPathPrefix. Default value is "".
218
*
219
* @return outputPathPrefix
220
*/
221
/* [PR 119756] config project prefix and postfix support in jpp_configuration.xml file */
222
public String getOutputPathPrefix() {
223
return outputPathPrefix;
224
}
225
226
/**
227
* Returns outputPathSuffix. Default value is "".
228
*
229
* @return outputPathSuffix
230
*/
231
/* [PR 119756] config project prefix and postfix support in jpp_configuration.xml file */
232
public String getOutputPathSuffix() {
233
return outputPathSuffix;
234
}
235
236
/**
237
* Returns testsOutputPathPrefix. Default value is "".
238
*
239
* @return testsOutputPathPrefix
240
*/
241
/* [PR 119756] config project prefix and postfix support in jpp_configuration.xml file */
242
public String getTestsOutputPathPrefix() {
243
return testsOutputPathPrefix;
244
}
245
246
/**
247
* Returns testsOutputPathSuffix. Default value is "".
248
*
249
* @return testsOutputPathSuffix
250
*/
251
/* [PR 119756] config project prefix and postfix support in jpp_configuration.xml file */
252
public String getTestsOutputPathSuffix() {
253
return testsOutputPathSuffix;
254
}
255
256
/**
257
* Returns bootTestsOutputPathPrefix. Default value is "".
258
*
259
* @return bootTestsOutputPathPrefix
260
*/
261
/* [PR 119756] config project prefix and postfix support in jpp_configuration.xml file */
262
public String getBootTestsOutputPathPrefix() {
263
return bootTestsOutputPathPrefix;
264
}
265
266
/**
267
* Returns bootTestsOutputPathSuffix. Default value is "".
268
*
269
* @return bootTestsOutputPathSuffix
270
*/
271
/* [PR 119756] config project prefix and postfix support in jpp_configuration.xml file */
272
public String getBootTestsOutputPathSuffix() {
273
return bootTestsOutputPathSuffix;
274
}
275
276
/**
277
* Returns the automated tests classpath entries.
278
*
279
* @return the automated tests classpath entries
280
*/
281
public List<ClassPathEntry> getTestsClassPaths() {
282
return testsClassPaths;
283
}
284
285
/**
286
* Returns the automated tests source entries.
287
*
288
* @return the automated tests source entries
289
*/
290
public List<Src> getTestsSources() {
291
return testsSources;
292
}
293
294
/**
295
* Parses the configuration XML file.
296
*
297
* @throws XMLException if there are errors in the XML file
298
*/
299
public void parseInput() throws XMLException {
300
System.out.println("Reading preprocess instructions from xml...");
301
new XMLParser().parse(XMLInput, this);
302
}
303
304
/**
305
* Insures that the base directory is not null.
306
*/
307
@Override
308
public void xmlStartDocument() {
309
if (baseDir == null) {
310
baseDir = "";
311
}
312
}
313
314
/**
315
* Resolves any configuration dependencies of the parsed configuration. One
316
* configuration may be dependant upon other configurations meaning that and
317
* preprocessor flags held by the by the depended upon configurations are
318
* inherited.
319
*/
320
@Override
321
public void xmlEndDocument() {
322
try {
323
XMLInput.close();
324
} catch (IOException e) {
325
System.err.println("Could not close ConfigXMLHandler InputStream");
326
e.printStackTrace();
327
}
328
}
329
330
/**
331
* A series of if statements to identify the significance of the parsed
332
* element and act accordingly.
333
*
334
* @param elementName the XML element name
335
* @param attributes the element's attributes
336
*
337
* @throws XMLException if there are errors in the XML file
338
*/
339
@Override
340
public void xmlStartElement(String elementName, Map<String, String> attributes) throws XMLException {
341
if (elementName.equals("configurationreg")) {
342
String version = attributes.get("version");
343
if (version == null) {
344
throw new XMLException("No JPP Configuration XML version defined");
345
} else {
346
int majorVersion = Integer.parseInt(version.substring(0, 1));
347
if (majorVersion > MAJOR_VERSION) {
348
throw new XMLException("Perprocessor can't handle JPP Configuration XML v" + majorVersion + ".x");
349
}
350
configVersion = majorVersion;
351
}
352
}
353
354
if (elementName.equals("automatedtests")) {
355
if (attributes.get("project") != null) {
356
inAutomatedTests = true;
357
testsProject = attributes.get("project");
358
}
359
} else if (elementName.equals("require") && attributes.get("name") != null) {
360
try {
361
ConfigurationRegistry requiredRegistry = MetaRegistry.getRegistry(baseDir, attributes.get("name"), ConfigurationRegistry.DEFAULT_XML);
362
requiredObjects.addAll(requiredRegistry.getConfigurationsAsCollection());
363
} catch (FileNotFoundException e) {
364
System.out.println("Could not find the XML configuration file: " + ConfigurationRegistry.DEFAULT_XML + "\n");
365
}
366
} else if (elementName.equals("set")) {
367
// Sets are groups of flags that are typically not used in a
368
// preprocessing job but insted act as dependencies for defined
369
// configurations.
370
371
currentConfig = new ConfigObject(attributes.get("label"), false);
372
if (attributes.get("flags") != null) {
373
StringTokenizer t = new StringTokenizer(attributes.get("flags"), ",");
374
375
while (t.hasMoreTokens()) {
376
String currentString = t.nextToken().trim();
377
/*
378
* You can specify that you wish a flag removed from the configuration or set with a preceding '-' character.
379
* For example if the final flag set (after dependency resolution) was: A, B, C and -A the '-A' would signify
380
* the removal of flag 'A' and only flags B and C would remain.
381
*/
382
if (currentString.charAt(0) == '-') {
383
currentConfig.addFlagToRemoveFlagSet(currentString.substring(1));
384
} else if (currentString.charAt(0) == '*') {
385
/*
386
* The '*' symbol prefixing any added flags is used when a required flag is needed. If a required flag is
387
* added to a configuration then for a java file to be accepted in preprocessing it must include at least
388
* the required flag and possibly others.
389
*/
390
currentConfig.addRequiredIncludeFlag(currentString.substring(1));
391
currentConfig.addFlag(currentString.substring(1));
392
} else {
393
currentConfig.addFlag(currentString);
394
}
395
}
396
}
397
398
/*
399
* Dependencies are other configurations or that can be incorporated into the current configuration (or set). For
400
* example if there existed a configuration called 'depX' with the flags Y and Z and the configuration 'configA'
401
* included flag A and the dependency on 'depX' then the final flag set of configA would be A, Y and Z.
402
*/
403
if (attributes.get("dependencies") != null) {
404
StringTokenizer t = new StringTokenizer(attributes.get("dependencies"), ",");
405
406
while (t.hasMoreTokens()) {
407
String currentString = t.nextToken().trim();
408
409
// Dependencies can be specified for removal just as flags
410
if (currentString.charAt(0) == '-') {
411
currentConfig.removeFlagDependency(currentString.substring(1));
412
} else {
413
currentConfig.addFlagDependency(currentString);
414
}
415
}
416
}
417
418
configObjects.add(currentConfig);
419
} else if (elementName.equals("configuration")) {
420
if (attributes.get("name") != null) {
421
currentConfig = new ConfigObject(attributes.get("name"), baseDir, true);
422
} else {
423
currentConfig = new ConfigObject(attributes.get("label"), baseDir, true);
424
if (attributes.get("flags") != null) {
425
StringTokenizer t = new StringTokenizer(attributes.get("flags"), ",");
426
while (t.hasMoreTokens()) {
427
String currentString = t.nextToken().trim();
428
if (currentString.charAt(0) == '-') {
429
currentConfig.addFlagToRemoveFlagSet(currentString.substring(1));
430
} else if (currentString.charAt(0) == '*') {
431
currentConfig.addRequiredIncludeFlag(currentString.substring(1));
432
currentConfig.addFlag(currentString.substring(1));
433
} else {
434
currentConfig.addFlag(currentString);
435
}
436
}
437
}
438
if (attributes.get("dependencies") != null) {
439
StringTokenizer t = new StringTokenizer(attributes.get("dependencies"), ",");
440
while (t.hasMoreTokens()) {
441
String currentString = t.nextToken().trim();
442
if (currentString.charAt(0) == '-') {
443
currentConfig.removeFlagDependency(currentString.substring(1));
444
} else {
445
currentConfig.addFlagDependency(currentString);
446
}
447
}
448
}
449
/* [PR 119756] config project prefix and postfix support in jpp_configuration.xml file */
450
// add global suffixes and prefixes
451
currentConfig.setOutputPathPrefix(outputPathPrefix);
452
currentConfig.setOutputPathSuffix(outputPathSuffix);
453
currentConfig.setTestsOutputPathPrefix(testsOutputPathPrefix);
454
currentConfig.setTestsOutputPathSuffix(testsOutputPathSuffix);
455
currentConfig.setBootTestsOutputPathPrefix(bootTestsOutputPathPrefix);
456
currentConfig.setBootTestsOutputPathSuffix(bootTestsOutputPathSuffix);
457
currentConfig.setDefaultTestsResourcesPrefixes(defaultTestsResources);
458
}
459
460
if (attributes.get("jdkcompliance") != null) {
461
currentConfig.setJDKCompliance(attributes.get("jdkcompliance"));
462
}
463
464
if (attributes.get("outputpath") != null) {
465
currentConfig.setOutputPathKeyword(attributes.get("outputpath"));
466
currentConfig.setOutputPath(attributes.get("outputpath"));
467
currentConfig.setTestsOutputPaths();
468
currentConfig.setBootTestsOutputPaths();
469
}
470
471
if (attributes.get("jppmetadata") != null) {
472
currentConfig.enableMetadata(attributes.get("jppmetadata").equals("true"));
473
}
474
475
configObjects.add(currentConfig);
476
} else if (elementName.equals("source")) {
477
String path = attributes.get("path");
478
if (!inAutomatedTests) {
479
path = (path.startsWith("/")) ? path : srcRoot + path;
480
}
481
482
if (attributes.get("type") != null && attributes.get("outputpath") != null) {
483
currentSource = new Src(path, attributes.get("outputpath"));
484
} else if (attributes.get("type") != null) {
485
currentSource = new Src(path, attributes.get("type").equals("simplecopy"));
486
} else {
487
currentSource = new Src(path);
488
}
489
490
inSource = true;
491
} else if (elementName.equals("parameter")) {
492
if (inSource) {
493
currentSource.addOption(attributes.get("name"), attributes.get("value"));
494
/* [PR 119756] config project prefix and postfix support in jpp_configuration.xml file */
495
} else if (inGlobals) {
496
if (attributes.get("name").equals("outputPathPrefix")) {
497
outputPathPrefix = attributes.get("value");
498
} else if (attributes.get("name").equals("outputPathSuffix")) {
499
outputPathSuffix = attributes.get("value");
500
} else if (attributes.get("name").equals("testsOutputPathPrefix")) {
501
testsOutputPathPrefix = attributes.get("value");
502
} else if (attributes.get("name").equals("testsOutputPathSuffix")) {
503
testsOutputPathSuffix = attributes.get("value");
504
} else if (attributes.get("name").equals("bootTestsOutputPathPrefix")) {
505
bootTestsOutputPathPrefix = attributes.get("value");
506
} else if (attributes.get("name").equals("bootTestsOutputPathSuffix")) {
507
bootTestsOutputPathSuffix = attributes.get("value");
508
} else {
509
System.out.println(attributes.get("name") + " is not valid global variable.");
510
}
511
} else {
512
/* [PR 119756] config project prefix and postfix support in jpp_configuration.xml file */
513
// if prefixes and suffixes are defined in configuration, then overwrite global values.
514
if (attributes.get("name").equals(outputPathPrefix)) {
515
currentConfig.setOutputPathPrefix(outputPathPrefix);
516
} else if (attributes.get("name").equals(outputPathSuffix)) {
517
currentConfig.setOutputPathSuffix(outputPathSuffix);
518
} else if (attributes.get("name").equals(testsOutputPathPrefix)) {
519
currentConfig.setTestsOutputPathPrefix(testsOutputPathPrefix);
520
} else if (attributes.get("name").equals(testsOutputPathSuffix)) {
521
currentConfig.setTestsOutputPathSuffix(testsOutputPathSuffix);
522
} else if (attributes.get("name").equals(bootTestsOutputPathPrefix)) {
523
currentConfig.setBootTestsOutputPathPrefix(bootTestsOutputPathPrefix);
524
} else if (attributes.get("name").equals(bootTestsOutputPathSuffix)) {
525
currentConfig.setBootTestsOutputPathSuffix(bootTestsOutputPathSuffix);
526
} else {
527
currentConfig.addOption(attributes.get("name"), attributes.get("value"));
528
}
529
}
530
/* [PR 118829] Desing 894: Core.JCL : Support for compiler options in preprocessor plugin */
531
} else if (elementName.equals("coption")) {
532
currentConfig.addCompilerOption(attributes.get("name"), attributes.get("value"));
533
} else if (elementName.equals("classpathentry")) {
534
boolean exported = Boolean.parseBoolean(attributes.get("exported"));
535
/* [PR 120359] New classpath entry is needed for configurations */
536
String kind = attributes.get("kind");
537
if (kind != null) {
538
String path = attributes.get("path");
539
String sourcepath = attributes.get("sourcepath");
540
ClassPathEntry entry;
541
if (sourcepath != null) {
542
entry = new ClassPathEntry(path, kind, sourcepath, exported);
543
} else {
544
entry = new ClassPathEntry(path, kind, exported);
545
}
546
classPaths.add(entry);
547
} else {
548
String registry = "this";
549
if (attributes.containsKey("registry")) {
550
registry = attributes.get("registry");
551
}
552
String configName = attributes.get("configName");
553
String project = attributes.get("project");
554
ConfigObject foundConfig = null;
555
String path = null;
556
if (registry.equals("this") || registry.equals(srcRoot.substring(0, srcRoot.length() - 1))) {
557
for (ConfigObject config : configObjects) {
558
if (config.isConfiguration() && config.getName().equals(configName)) {
559
foundConfig = config;
560
break;
561
}
562
}
563
} else {
564
try {
565
// the following two lines are risky in some cases,
566
// for example, if current registry needs an config from another registry and another registry needs a
567
// config from current registry,
568
// this may cause a loop and you might see overflow exception on the window,
569
// This part might be removed or can have better solution,
570
// Be aware that we dont point to another registry for now, and really low possibility in the future to
571
// point a registry from an other registry.
572
ConfigurationRegistry configReg = MetaRegistry.getRegistry(baseDir, registry, ConfigurationRegistry.DEFAULT_XML);
573
foundConfig = configReg.getConfiguration(configName);
574
} catch (FileNotFoundException e) {
575
if (currentConfig != null) {
576
currentConfig.setXMLParserError("XML PARSER ERROR : Config : " + currentConfig.getName()
577
+ ", Element : \"classpathentry\", Reason : registry could not be found : " + baseDir
578
+ (registry.equals("this") ? srcRoot : (registry + File.separator)) + ConfigurationRegistry.DEFAULT_XML + "\n");
579
}
580
}
581
}
582
if (foundConfig != null) {
583
if (project.equals("config")) {
584
path = "/" + foundConfig.getOutputPathPrefix() + foundConfig.getOutputPathKeyword() + foundConfig.getOutputPathSuffix();
585
} else if (project.equals("tests")) {
586
path = "/" + foundConfig.getTestsOutputPathPrefix() + foundConfig.getOutputPathKeyword() + foundConfig.getTestsOutputPathSuffix();
587
} else if (project.equals("boottests")) {
588
path = "/" + foundConfig.getBootTestsOutputPathPrefix() + foundConfig.getOutputPathKeyword() + foundConfig.getBootTestsOutputPathSuffix();
589
} else {
590
if (currentConfig != null) {
591
currentConfig.setXMLParserError("XML PARSER ERROR : Attribute \"project\" can have the value \"config\", \"tests\" or \"boottests\"\n");
592
}
593
}
594
classPaths.add(new ClassPathEntry(path, "src", exported));
595
} else {
596
if (currentConfig != null) {
597
currentConfig.setXMLParserError("XML PARSER ERROR : Config : " + currentConfig.getName()
598
+ ", Element : \"classpathentry\", Reason : pointed config in classpathentry element could not be found. Pointed Config Name : " + configName
599
+ "\n");
600
}
601
}
602
}
603
} else if (elementName.equals("dependjob")) {
604
String dependJobName = attributes.get("config");
605
String dependJobRegistry = attributes.get("registry");
606
ConfigurationRegistry dependRegistry = null;
607
608
try {
609
dependRegistry = MetaRegistry.getRegistry(baseDir, dependJobRegistry, ConfigurationRegistry.DEFAULT_XML);
610
} catch (FileNotFoundException e) {
611
System.out.println("Could not find the XML configuration file: /" + dependJobRegistry + "/" + ConfigurationRegistry.DEFAULT_XML + "\n");
612
} finally {
613
ConfigObject dependJob = (dependRegistry != null) ? dependRegistry.getConfiguration(dependJobName) : null;
614
currentConfig.addDependJob(dependJobRegistry + " - " + dependJobName, dependJob);
615
}
616
} else if (elementName.equals("globalParameters")) {
617
inGlobals = true;
618
/* [PR 121295] Support for resources' prefixes and directories */
619
} else if (elementName.equals("testsResources")) {
620
if (attributes.containsKey("defaults")) {
621
String defaults = attributes.get("defaults");
622
if (defaults.equals("true") && !inAutomatedTests) {
623
currentConfig.setUseTestResourcesDefaults(true);
624
}
625
} else {
626
String dir = attributes.get("directory");
627
String prefix = attributes.get("prefix");
628
629
if (inAutomatedTests) {
630
String dirSlash = dir + "/";
631
632
for (Iterator<String> iter = defaultTestsResources.keySet().iterator(); iter.hasNext();) {
633
String nextDir = iter.next();
634
635
if (nextDir.startsWith(dirSlash) || nextDir.equals(dir)) {
636
iter.remove();
637
}
638
}
639
defaultTestsResources.put(dir, prefix);
640
} else {
641
currentConfig.setTestsResourcesPrefix(dir, prefix);
642
}
643
}
644
}
645
}
646
647
/**
648
* Defines what action need be taken at the end of the certain elements.
649
*
650
* @param elementName the XML element name
651
*/
652
@Override
653
public void xmlEndElement(String elementName) {
654
if (elementName.equals("automatedtests")) {
655
testsClassPaths.addAll(classPaths);
656
classPaths.clear();
657
inAutomatedTests = false;
658
} else if (elementName.equals("configuration") || elementName.equals("set")) {
659
for (ClassPathEntry classPath : classPaths) {
660
currentConfig.addClassPathEntry(classPath);
661
}
662
classPaths.clear();
663
currentConfig = null;
664
} else if (elementName.equals("source")) {
665
if (inAutomatedTests) {
666
testsSources.add(currentSource);
667
} else {
668
currentConfig.addSource(currentSource);
669
}
670
currentSource = null;
671
inSource = false;
672
/* [PR 119756] config project prefix and postfix support in jpp_configuration.xml file */
673
} else if (elementName.equals("globalParameters")) {
674
inGlobals = false;
675
}
676
}
677
678
/**
679
* Unused section of the interface
680
*
681
* @param chars
682
*/
683
@Override
684
public void xmlCharacters(String chars) {
685
// System.out.println("xmlChars: " + chars);
686
}
687
688
}
689
690