Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x.x] Ensure that EXPath packages installed in $EXIST_HOME/data/expathrepo are filesystem portable #4913

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions exist-core/src/main/java/org/exist/repo/ClasspathHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -74,7 +75,7 @@ public static void updateClasspath(BrokerPool pool, org.expath.pkg.repo.Package
final Path packageDir = resolver.resolveResourceAsFile(".");
final Classpath cp = new Classpath();
try {
scanPackageDir(cp, packageDir);
scanPackageDir(pkg, cp, packageDir);
((EXistClassLoader)loader).addURLs(cp);
} catch (final IOException e) {
LOG.warn("An error occurred while updating classpath for package {}", pkg.getName(), e);
Expand All @@ -93,7 +94,7 @@ private static void scanPackages(BrokerPool pool, Classpath classpath) {
try {
final FileSystemStorage.FileSystemResolver resolver = (FileSystemStorage.FileSystemResolver) pkg.getResolver();
final Path packageDir = resolver.resolveResourceAsFile(".");
scanPackageDir(classpath, packageDir);
scanPackageDir(pkg, classpath, packageDir);
} catch (final IOException e) {
LOG.warn("An error occurred while updating classpath for package {}", pkg.getName(), e);
}
Expand Down Expand Up @@ -157,7 +158,7 @@ private static boolean isCompatible(final Package pkg) throws PackageException {
}
}

private static void scanPackageDir(Classpath classpath, Path module) throws IOException {
private static void scanPackageDir(Package pkg, Classpath classpath, Path module) throws IOException {
final Path dotExist = module.resolve(".exist");
if (Files.exists(dotExist)) {
if (!Files.isDirectory(dotExist)) {
Expand All @@ -169,7 +170,18 @@ private static void scanPackageDir(Classpath classpath, Path module) throws IOEx
try (final BufferedReader reader = Files.newBufferedReader(cp)) {
String line;
while ((line = reader.readLine()) != null) {
classpath.addComponent(line);
Path p = Paths.get(line);
if (!p.isAbsolute()) {
final FileSystemStorage.FileSystemResolver res = (FileSystemStorage.FileSystemResolver) pkg.getResolver();
p = res.resolveComponentAsFile(line);
}
p = p.normalize().toAbsolutePath();

if (Files.exists(p)) {
classpath.addComponent(p.toString());
} else {
LOG.warn("Unable to add '" + p + "' to the classpath for EXPath package: " + pkg.getName() + ", as the file does not exist!");
}
}
}
}
Expand Down
22 changes: 9 additions & 13 deletions exist-core/src/main/java/org/exist/repo/ExistPkgExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.stream.StreamSource;
import java.io.IOException;
import java.io.Writer;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Set;

/**
* Handle the exist.xml descriptor in an EXPath package.
Expand Down Expand Up @@ -158,23 +155,22 @@ private void setupPackage(Package pkg, ExistPkgInfo info)
throw new PackageException("Impossible to create directory: " + exist);
}
}
final Set<String> jars = info.getJars();

try(final Writer out = Files.newBufferedWriter(classpath)) {
for (final String jar : jars) {
StreamSource jar_src;
for (final String jar : info.getJars()) {

try {
jar_src = res.resolveComponent(jar);
res.resolveComponent(jar);
} catch (final NotExistException ex) {
final String msg = "Inconsistent package descriptor, the JAR file is not in the package: ";
final String msg = "Inconsistent package descriptor, the JAR file is not in the EXPath package: ";
throw new PackageException(msg + jar, ex);
}
final URI uri = URI.create(jar_src.getSystemId());
final Path file = Paths.get(uri);
out.write(file.normalize().toString());
out.write("\n");

out.write(jar);
out.write('\n');
}
} catch (final IOException ex) {
throw new PackageException("Error writing the eXist classpath file: " + classpath, ex);
throw new PackageException("Error writing the eXist classpath file '" + classpath + "' for the EXPath package: " + pkg.getName(), ex);
}
}

Expand Down
Loading