Search in sources :

Example 1 with InstallException

use of org.crosswire.jsword.book.install.InstallException in project step by STEPBible.

the class JSwordModuleServiceImpl method reloadInstallers.

@Override
public void reloadInstallers() {
    boolean errors = false;
    LOGGER.trace("About to reload installers");
    final List<Installer> installers = getInstallers();
    for (final Installer i : installers) {
        try {
            LOGGER.trace("Reloading installer [{}]", i.getInstallerDefinition());
            i.reloadBookList();
        } catch (final InstallException e) {
            errors = true;
            LOGGER.error(e.getMessage(), e);
        }
    }
    if (errors) {
        throw new StepInternalException("Errors occurred while trying to retrieve the latest installer information");
    }
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) DirectoryListingInstaller(com.tyndalehouse.step.core.data.DirectoryListingInstaller) Installer(org.crosswire.jsword.book.install.Installer) BibleInstaller(com.tyndalehouse.step.core.models.BibleInstaller) InstallException(org.crosswire.jsword.book.install.InstallException)

Example 2 with InstallException

use of org.crosswire.jsword.book.install.InstallException in project step by STEPBible.

the class JSwordModuleServiceImpl method installFromInstallers.

private void installFromInstallers(final String initials, List<Installer> installers) {
    LOGGER.debug("Installing module [{}]", initials);
    notBlank(initials, "No version was found", SERVICE_VALIDATION_ERROR);
    // check if already installed?
    if (!isInstalled(initials)) {
        LOGGER.debug("Book was not already installed, so kicking off installation process for [{}]", initials);
        for (final Installer i : installers) {
            // long initials
            String longInitials = this.versionResolver.getLongName(initials);
            final Book bookToBeInstalled = i.getBook(longInitials);
            if (bookToBeInstalled != null) {
                // then we can kick off installation and return
                try {
                    i.install(bookToBeInstalled);
                    return;
                } catch (final InstallException e) {
                    // we log error here,
                    LOGGER.error("An error occurred error, and we unable to use this installer for module" + initials, e);
                    // but go round the loop to see if more options are available
                    continue;
                }
            }
        }
        // if we get here, then we were unable to install the book
        // since we couldn't find it.
        LOGGER.error("Unable to install: [{}]", initials);
        throw new TranslatedException("book_not_found", initials);
    }
    // if we get here then we had already installed the book - how come we're asking for this again?
    LOGGER.warn("A request to install an already installed book was made for initials " + initials);
}
Also used : DirectoryListingInstaller(com.tyndalehouse.step.core.data.DirectoryListingInstaller) Installer(org.crosswire.jsword.book.install.Installer) BibleInstaller(com.tyndalehouse.step.core.models.BibleInstaller) TranslatedException(com.tyndalehouse.step.core.exceptions.TranslatedException) Book(org.crosswire.jsword.book.Book) InstallException(org.crosswire.jsword.book.install.InstallException)

Example 3 with InstallException

use of org.crosswire.jsword.book.install.InstallException in project step by STEPBible.

the class JSwordModuleServiceImpl method getAllModules.

@Override
public List<Book> getAllModules(int installerIndex, final BookCategory... bibleCategory) {
    final List<Book> books = new ArrayList<Book>();
    List<Installer> installers = getInstallers();
    if (installerIndex != -1) {
        // use a single installer
        Installer installer = installers.get(installerIndex);
        installers = new ArrayList<Installer>();
        installers.add(installer);
    }
    for (final Installer installer : installers) {
        try {
            installer.reloadBookList();
            final List<Book> installerBooks = installer.getBooks();
            // - 4 items bigs, likely 2
            for (final Book b : installerBooks) {
                for (final BookCategory cat : bibleCategory) {
                    if (cat.equals(b.getBookCategory())) {
                        books.add(b);
                        break;
                    }
                }
            }
        } catch (final InstallException e) {
            // log an error
            LOGGER.error("Unable to update installer", e);
        }
    }
    return books;
}
Also used : BookCategory(org.crosswire.jsword.book.BookCategory) DirectoryListingInstaller(com.tyndalehouse.step.core.data.DirectoryListingInstaller) Installer(org.crosswire.jsword.book.install.Installer) BibleInstaller(com.tyndalehouse.step.core.models.BibleInstaller) Book(org.crosswire.jsword.book.Book) ArrayList(java.util.ArrayList) InstallException(org.crosswire.jsword.book.install.InstallException)

Example 4 with InstallException

use of org.crosswire.jsword.book.install.InstallException in project step by STEPBible.

the class DirectoryInstaller method download.

@Override
protected void download(final Progress job, final String packageDir, final String file, final URI dest) throws InstallException {
    final File sourceFile = new File(super.getPackageDirectory(), file);
    // copy two streams
    InputStream source = null;
    OutputStream target = null;
    try {
        target = new BufferedOutputStream(new FileOutputStream(new File(dest)));
        source = new BufferedInputStream(new FileInputStream(sourceFile));
        final byte[] buffer = new byte[1024];
        int length = 0;
        while ((length = source.read(buffer)) > 0) {
            target.write(buffer, 0, length);
        }
    } catch (final FileNotFoundException e) {
        throw new InstallException("File not found (either source or destination). Unable to open stream to copy file.", e);
    } catch (final IOException e) {
        throw new InstallException("General IOException. Can't read/write to specified files", e);
    } finally {
        IOUtil.close(source);
        IOUtil.close(target);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) InstallException(org.crosswire.jsword.book.install.InstallException) FileInputStream(java.io.FileInputStream)

Example 5 with InstallException

use of org.crosswire.jsword.book.install.InstallException in project step by STEPBible.

the class DirectoryListingInstaller method reloadBookList.

/* (non-Javadoc)
     * @see org.crosswire.jsword.book.install.Installer#reloadBookList()
     */
public void reloadBookList() throws InstallException {
    // TRANSLATOR: Progress label for downloading one or more files.
    String jobName = JSMsg.gettext("Downloading files");
    Progress job = JobManager.createJob(Progress.RELOAD_BOOK_LIST, jobName, Thread.currentThread());
    job.beginJob(jobName);
    try {
        loaded = false;
        loadCachedIndex();
    } catch (InstallException ex) {
        job.cancel();
        throw ex;
    } finally {
        job.done();
    }
}
Also used : Progress(org.crosswire.common.progress.Progress) InstallException(org.crosswire.jsword.book.install.InstallException)

Aggregations

InstallException (org.crosswire.jsword.book.install.InstallException)6 DirectoryListingInstaller (com.tyndalehouse.step.core.data.DirectoryListingInstaller)3 BibleInstaller (com.tyndalehouse.step.core.models.BibleInstaller)3 Installer (org.crosswire.jsword.book.install.Installer)3 StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)2 File (java.io.File)2 IOException (java.io.IOException)2 Book (org.crosswire.jsword.book.Book)2 TranslatedException (com.tyndalehouse.step.core.exceptions.TranslatedException)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 FilenameFilter (java.io.FilenameFilter)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 Progress (org.crosswire.common.progress.Progress)1 BookCategory (org.crosswire.jsword.book.BookCategory)1