Skip to content

Commit dfa75e1

Browse files
authored
Merge pull request #4902 from evolvedbinary/hotfix/expath-pkg-classpath
Ensure that EXPath packages installed in $EXIST_HOME/data/expathrepo are filesystem portable
2 parents 1f4a6a4 + c3e4c1e commit dfa75e1

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.net.URI;
4040
import java.nio.file.Files;
4141
import java.nio.file.Path;
42+
import java.nio.file.Paths;
4243
import java.util.Collection;
4344
import java.util.Optional;
4445
import java.util.Set;
@@ -74,7 +75,7 @@ public static void updateClasspath(BrokerPool pool, org.expath.pkg.repo.Package
7475
final Path packageDir = resolver.resolveResourceAsFile(".");
7576
final Classpath cp = new Classpath();
7677
try {
77-
scanPackageDir(cp, packageDir);
78+
scanPackageDir(pkg, cp, packageDir);
7879
((EXistClassLoader)loader).addURLs(cp);
7980
} catch (final IOException e) {
8081
LOG.warn("An error occurred while updating classpath for package {}", pkg.getName(), e);
@@ -93,7 +94,7 @@ private static void scanPackages(BrokerPool pool, Classpath classpath) {
9394
try {
9495
final FileSystemStorage.FileSystemResolver resolver = (FileSystemStorage.FileSystemResolver) pkg.getResolver();
9596
final Path packageDir = resolver.resolveResourceAsFile(".");
96-
scanPackageDir(classpath, packageDir);
97+
scanPackageDir(pkg, classpath, packageDir);
9798
} catch (final IOException e) {
9899
LOG.warn("An error occurred while updating classpath for package {}", pkg.getName(), e);
99100
}
@@ -157,7 +158,7 @@ private static boolean isCompatible(final Package pkg) throws PackageException {
157158
}
158159
}
159160

160-
private static void scanPackageDir(Classpath classpath, Path module) throws IOException {
161+
private static void scanPackageDir(Package pkg, Classpath classpath, Path module) throws IOException {
161162
final Path dotExist = module.resolve(".exist");
162163
if (Files.exists(dotExist)) {
163164
if (!Files.isDirectory(dotExist)) {
@@ -169,7 +170,18 @@ private static void scanPackageDir(Classpath classpath, Path module) throws IOEx
169170
try (final BufferedReader reader = Files.newBufferedReader(cp)) {
170171
String line;
171172
while ((line = reader.readLine()) != null) {
172-
classpath.addComponent(line);
173+
Path p = Paths.get(line);
174+
if (!p.isAbsolute()) {
175+
final FileSystemStorage.FileSystemResolver res = (FileSystemStorage.FileSystemResolver) pkg.getResolver();
176+
p = res.resolveComponentAsFile(line);
177+
}
178+
p = p.normalize().toAbsolutePath();
179+
180+
if (Files.exists(p)) {
181+
classpath.addComponent(p.toString());
182+
} else {
183+
LOG.warn("Unable to add '" + p + "' to the classpath for EXPath package: " + pkg.getName() + ", as the file does not exist!");
184+
}
173185
}
174186
}
175187
}

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,12 @@
3232
import javax.xml.stream.XMLStreamConstants;
3333
import javax.xml.stream.XMLStreamException;
3434
import javax.xml.stream.XMLStreamReader;
35-
import javax.xml.transform.stream.StreamSource;
3635
import java.io.IOException;
3736
import java.io.Writer;
3837
import java.net.URI;
3938
import java.net.URISyntaxException;
4039
import java.nio.file.Files;
4140
import java.nio.file.Path;
42-
import java.nio.file.Paths;
43-
import java.util.Set;
4441

4542
/**
4643
* Handle the exist.xml descriptor in an EXPath package.
@@ -158,23 +155,22 @@ private void setupPackage(Package pkg, ExistPkgInfo info)
158155
throw new PackageException("Impossible to create directory: " + exist);
159156
}
160157
}
161-
final Set<String> jars = info.getJars();
158+
162159
try(final Writer out = Files.newBufferedWriter(classpath)) {
163-
for (final String jar : jars) {
164-
StreamSource jar_src;
160+
for (final String jar : info.getJars()) {
161+
165162
try {
166-
jar_src = res.resolveComponent(jar);
163+
res.resolveComponent(jar);
167164
} catch (final NotExistException ex) {
168-
final String msg = "Inconsistent package descriptor, the JAR file is not in the package: ";
165+
final String msg = "Inconsistent package descriptor, the JAR file is not in the EXPath package: ";
169166
throw new PackageException(msg + jar, ex);
170167
}
171-
final URI uri = URI.create(jar_src.getSystemId());
172-
final Path file = Paths.get(uri);
173-
out.write(file.normalize().toString());
174-
out.write("\n");
168+
169+
out.write(jar);
170+
out.write('\n');
175171
}
176172
} catch (final IOException ex) {
177-
throw new PackageException("Error writing the eXist classpath file: " + classpath, ex);
173+
throw new PackageException("Error writing the eXist classpath file '" + classpath + "' for the EXPath package: " + pkg.getName(), ex);
178174
}
179175
}
180176

0 commit comments

Comments
 (0)