use of org.expath.pkg.repo.Storage.NotExistException in project exist by eXist-db.
the class ExistPkgExtension method setupPackage.
// TODO: Must not be here (in the parsing class). See the comment at the
// end of parseDescriptor().
private void setupPackage(Package pkg, ExistPkgInfo info) throws PackageException {
// TODO: FIXME: Bad, BAD design! But will be resolved naturally by moving the
// install code within the storage class (because we are writing on disk)...
final FileSystemResolver res = (FileSystemResolver) pkg.getResolver();
final Path classpath = res.resolveResourceAsFile(".exist/classpath.txt");
// create [pkg_dir]/.exist/classpath.txt if not already
final Path exist = classpath.getParent();
if (!Files.exists(exist)) {
try {
Files.createDirectories(exist);
} catch (final IOException e) {
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;
try {
jar_src = res.resolveComponent(jar);
} catch (final NotExistException ex) {
final String msg = "Inconsistent package descriptor, the JAR file is not in the 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");
}
} catch (final IOException ex) {
throw new PackageException("Error writing the eXist classpath file: " + classpath, ex);
}
}
use of org.expath.pkg.repo.Storage.NotExistException in project exist by eXist-db.
the class ExistPkgExtension method parseDescriptor.
@Override
protected void parseDescriptor(XMLStreamReader parser, Package pkg) throws PackageException {
myXSHelper.ensureNextElement(parser, "package");
final ExistPkgInfo info = new ExistPkgInfo(pkg);
try {
parser.next();
while (parser.getEventType() == XMLStreamConstants.START_ELEMENT) {
if (EXIST_PKG_NS.equals(parser.getNamespaceURI())) {
handleElement(parser, pkg, info);
} else {
// TODO: FIXME: Actually ignore (pass it.)
throw new PackageException("TODO: Ignore elements in other namespace");
}
parser.next();
}
// position to </package>
parser.next();
} catch (final XMLStreamException ex) {
throw new PackageException("Error reading the exist descriptor", ex);
}
pkg.addInfo(getName(), info);
// phase though (during the "xrepo install").
if (!info.getJars().isEmpty()) {
try {
pkg.getResolver().resolveResource(".exist/classpath.txt");
} catch (final NotExistException ex) {
setupPackage(pkg, info);
}
}
}
Aggregations