Search in sources :

Example 1 with NotExistException

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);
    }
}
Also used : Path(java.nio.file.Path) StreamSource(javax.xml.transform.stream.StreamSource) PackageException(org.expath.pkg.repo.PackageException) NotExistException(org.expath.pkg.repo.Storage.NotExistException) IOException(java.io.IOException) URI(java.net.URI) Writer(java.io.Writer) FileSystemResolver(org.expath.pkg.repo.FileSystemStorage.FileSystemResolver)

Example 2 with NotExistException

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);
        }
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) PackageException(org.expath.pkg.repo.PackageException) NotExistException(org.expath.pkg.repo.Storage.NotExistException)

Aggregations

PackageException (org.expath.pkg.repo.PackageException)2 NotExistException (org.expath.pkg.repo.Storage.NotExistException)2 IOException (java.io.IOException)1 Writer (java.io.Writer)1 URI (java.net.URI)1 Path (java.nio.file.Path)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 StreamSource (javax.xml.transform.stream.StreamSource)1 FileSystemResolver (org.expath.pkg.repo.FileSystemStorage.FileSystemResolver)1