Skip to content

Commit 6a9bd0d

Browse files
authored
Merge pull request #4589 from evolvedbinary/hotfix/xsuite-xqsuite
Fixes an issue with XSuite not being able to run some formulations of XQsuite
2 parents c9bd9c1 + 02a3635 commit 6a9bd0d

File tree

12 files changed

+352
-94
lines changed

12 files changed

+352
-94
lines changed

exist-core/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@
693693
<exclude>src/main/java/org/exist/util/CollectionOfArrayIterator.java</exclude>
694694
<exclude>src/test/java/org/exist/util/CollectionOfArrayIteratorTest.java</exclude>
695695
<exclude>src/main/java/org/exist/util/IPUtil.java</exclude>
696+
<exclude>src/main/java/org/exist/util/MapUtil.java</exclude>
696697
<exclude>src/main/java/org/exist/xmlrpc/ACEAiderParser.java</exclude>
697698
<exclude>src/main/java/org/exist/xmlrpc/ACEAiderSerializer.java</exclude>
698699
<exclude>src/main/java/org/exist/xquery/Cardinality.java</exclude>
@@ -841,6 +842,7 @@ The original license statement is also included below.]]></preamble>
841842
<include>src/main/java/org/exist/util/CollectionOfArrayIterator.java</include>
842843
<include>src/test/java/org/exist/util/CollectionOfArrayIteratorTest.java</include>
843844
<include>src/main/java/org/exist/util/IPUtil.java</include>
845+
<include>src/main/java/org/exist/util/MapUtil.java</include>
844846
<include>src/main/java/org/exist/xmlrpc/ACEAiderParser.java</include>
845847
<include>src/main/java/org/exist/xmlrpc/ACEAiderSerializer.java</include>
846848
<include>src/main/java/org/exist/xquery/Cardinality.java</include>

exist-core/src/main/java/org/exist/repo/ExistRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void configure(final Configuration configuration) throws BrokerPoolServic
8787

8888
@Override
8989
public void prepare(final BrokerPool brokerPool) throws BrokerPoolServiceException {
90-
if(!Files.exists(expathDir)) {
90+
if (!Files.exists(expathDir) && brokerPool != null) {
9191
moveOldRepo(brokerPool.getConfiguration().getExistHome(), expathDir);
9292
}
9393
try {

exist-core/src/main/java/org/exist/storage/BrokerPool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ private void _initialize() throws EXistException, DatabaseConfigurationException
506506

507507
this.symbols = servicesManager.register(new SymbolTable());
508508

509-
this.expathRepo = Optional.ofNullable(new ExistRepository());
509+
this.expathRepo = Optional.of(new ExistRepository());
510510
expathRepo.ifPresent(servicesManager::register);
511511
servicesManager.register(new ClasspathHelper());
512512

exist-core/src/main/java/org/exist/test/runner/XQueryTestRunner.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
import com.evolvedbinary.j8fu.tuple.Tuple2;
2626
import org.exist.EXistException;
2727
import org.exist.dom.QName;
28+
import org.exist.repo.ExistRepository;
2829
import org.exist.security.PermissionDeniedException;
2930
import org.exist.source.ClassLoaderSource;
3031
import org.exist.source.FileSource;
3132
import org.exist.source.Source;
3233
import org.exist.storage.BrokerPool;
34+
import org.exist.storage.BrokerPoolServiceException;
3335
import org.exist.util.Configuration;
3436
import org.exist.util.ConfigurationHelper;
3537
import org.exist.util.DatabaseConfigurationException;
@@ -88,7 +90,17 @@ private static Configuration getConfiguration() throws DatabaseConfigurationExce
8890
private static XQueryTestInfo extractTestInfo(final Path path) throws InitializationError {
8991
try {
9092
final Configuration config = getConfiguration();
93+
94+
final ExistRepository expathRepo = new ExistRepository();
95+
try {
96+
expathRepo.configure(config);
97+
expathRepo.prepare(null);
98+
} catch (final BrokerPoolServiceException e) {
99+
throw new InitializationError(e);
100+
}
101+
91102
final XQueryContext xqueryContext = new XQueryContext(config);
103+
xqueryContext.setTestRepository(Optional.of(expathRepo));
92104

93105
final Source xquerySource = new FileSource(path, UTF_8, false);
94106
final XQuery xquery = new XQuery();
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (C) 2014, Evolved Binary Ltd
3+
*
4+
* This file was originally ported from FusionDB to eXist-db by
5+
* Evolved Binary, for the benefit of the eXist-db Open Source community.
6+
* Only the ported code as it appears in this file, at the time that
7+
* it was contributed to eXist-db, was re-licensed under The GNU
8+
* Lesser General Public License v2.1 only for use in eXist-db.
9+
*
10+
* This license grant applies only to a snapshot of the code as it
11+
* appeared when ported, it does not offer or infer any rights to either
12+
* updates of this source code or access to the original source code.
13+
*
14+
* The GNU Lesser General Public License v2.1 only license follows.
15+
*
16+
* ---------------------------------------------------------------------
17+
*
18+
* Copyright (C) 2014, Evolved Binary Ltd
19+
*
20+
* This library is free software; you can redistribute it and/or
21+
* modify it under the terms of the GNU Lesser General Public
22+
* License as published by the Free Software Foundation; version 2.1.
23+
*
24+
* This library is distributed in the hope that it will be useful,
25+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27+
* Lesser General Public License for more details.
28+
*
29+
* You should have received a copy of the GNU Lesser General Public
30+
* License along with this library; if not, write to the Free Software
31+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
32+
*/
33+
package org.exist.util;
34+
35+
import com.evolvedbinary.j8fu.tuple.Tuple2;
36+
37+
import java.util.HashMap;
38+
import java.util.Map;
39+
40+
/**
41+
* Simple utility functions for working with Java Maps.
42+
*
43+
* @author <a href="mailto:[email protected]">Adam Retter</a>
44+
*/
45+
public interface MapUtil {
46+
47+
/**
48+
* Create a Hash Map from a List of Tuples.
49+
*
50+
* @param <K> the type of the keys in the map.
51+
* @param <V> the types of the values in the map.
52+
*
53+
* @param entries the entries for the map.
54+
*
55+
* @return The HashMap
56+
*/
57+
static <K, V> Map<K,V> HashMap(final Tuple2<K, V>... entries) {
58+
return HashMap(Math.max(entries.length, 16), entries);
59+
}
60+
61+
/**
62+
* Create a Hash Map from a List of Tuples.
63+
*
64+
* @param <K> the type of the keys in the map.
65+
* @param <V> the types of the values in the map.
66+
*
67+
* @param initialCapacity allows you to oversize the map if you plan to add more entries.
68+
* @param entries the entries for the map.
69+
*
70+
* @return The HashMap
71+
*/
72+
static <K, V> Map<K,V> HashMap(final int initialCapacity, final Tuple2<K, V>... entries) {
73+
final Map<K, V> map = new HashMap<>(initialCapacity);
74+
for (final Tuple2<K, V> entry : entries) {
75+
map.put(entry._1, entry._2);
76+
}
77+
return map;
78+
}
79+
}

exist-core/src/main/java/org/exist/xquery/ModuleContext.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,18 @@ public class ModuleContext extends XQueryContext {
6565

6666
public ModuleContext(final XQueryContext parentContext, final String modulePrefix, final String moduleNamespace,
6767
final String location) {
68-
super();
68+
super(parentContext != null ? parentContext.db : null,
69+
parentContext != null ? parentContext.getConfiguration() : null,
70+
null,
71+
false);
72+
6973
this.modulePrefix = modulePrefix;
7074
this.moduleNamespace = moduleNamespace;
7175
this.location = location;
76+
7277
setParentContext(parentContext);
7378

74-
loadDefaults(getConfiguration());
75-
this.profiler = new Profiler(getBroker() != null ? getBroker().getBrokerPool() : null);
79+
loadDefaults(this.configuration);
7680
}
7781

7882
@Override
@@ -103,7 +107,6 @@ private void setParentContext(final XQueryContext parentContext) {
103107
this.parentContext = parentContext;
104108
//XXX: raise error on null!
105109
if (parentContext != null) {
106-
this.db = parentContext.db;
107110
this.baseURI = parentContext.baseURI;
108111
try {
109112
if (location.startsWith(XmldbURI.XMLDB_URI_PREFIX) ||
@@ -183,11 +186,6 @@ public XQueryContext copyContext() {
183186
return ctx;
184187
}
185188

186-
@Override
187-
public Configuration getConfiguration() {
188-
return parentContext.getConfiguration();
189-
}
190-
191189
@Override
192190
public void addDynamicOption(final String name, final String value) throws XPathException {
193191
parentContext.addDynamicOption(name, value);

0 commit comments

Comments
 (0)