Search in sources :

Example 1 with InstallerException

use of de.janrufmonitor.framework.installer.InstallerException in project janrufmonitor by tbrandt77.

the class UpdateWizard method performFinish.

public boolean performFinish() {
    final List l = ((UpdatesPage) this.m_pages[0]).getResult();
    final boolean isMoreUpdates = ((UpdatesPage) this.m_pages[0]).isMoreUpdates();
    if (l.size() > 0) {
        try {
            IRunnableWithProgress op = new IRunnableWithProgress() {

                public void run(IProgressMonitor pm) throws InvocationTargetException, InterruptedException {
                    pm.setTaskName(m_i18n.getString(getNamespace(), "updates", "label", m_language));
                    Properties p = null;
                    String url, name = null;
                    StreamRequester sr = null;
                    for (int i = 0, n = l.size(); i < n; i++) {
                        p = (Properties) l.get(i);
                        url = p.getProperty(InstallerConst.DESCRIPTOR_UPDATE);
                        name = p.getProperty(InstallerConst.DESCRIPTOR_NAME) + "." + p.getProperty(InstallerConst.DESCRIPTOR_VERSION) + InstallerConst.EXTENSION_ARCHIVE;
                        if (url != null && url.length() > 6) {
                            pm.subTask(m_i18n.getString(getNamespace(), "install", "label", m_language) + name);
                            sr = new StreamRequester(url);
                            sr.go();
                            try {
                                InstallerEngine.getInstance().install(name, sr.getInputStream(), (i == (n - 1)));
                            } catch (InstallerException e) {
                                m_logger.severe(e.getMessage());
                                PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "failed", new Exception("Installation failed for module " + url)));
                            }
                        }
                    }
                    DisplayManager.getDefaultDisplay().asyncExec(new Runnable() {

                        public void run() {
                            MessageDialog.openInformation(getShell(), m_i18n.getString(getNamespace(), "success", "label", m_language), m_i18n.getString(getNamespace(), "success", "description", m_language));
                            m_finished = true;
                        }
                    });
                    if (isMoreUpdates) {
                        DisplayManager.getDefaultDisplay().asyncExec(new Runnable() {

                            public void run() {
                                MessageDialog.openInformation(getShell(), m_i18n.getString(getNamespace(), "moreupdates", "label", m_language), m_i18n.getString(getNamespace(), "moreupdates", "description", m_language));
                                m_finished = true;
                            }
                        });
                    }
                }
            };
            ProgressMonitorDialog pmd = new ProgressMonitorDialog(getShell());
            pmd.run(true, true, op);
        } catch (InvocationTargetException e) {
            this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            m_finished = true;
        } catch (InterruptedException e) {
            this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            m_finished = true;
        }
    }
    while (!m_finished) {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            m_finished = true;
        }
    }
    return true;
}
Also used : Message(de.janrufmonitor.exception.Message) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Properties(java.util.Properties) InstallerException(de.janrufmonitor.framework.installer.InstallerException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) InstallerException(de.janrufmonitor.framework.installer.InstallerException) UpdatesPage(de.janrufmonitor.ui.jface.wizards.pages.UpdatesPage)

Example 2 with InstallerException

use of de.janrufmonitor.framework.installer.InstallerException in project janrufmonitor by tbrandt77.

the class ConsoleUpdate method execute.

public void execute() {
    this.isExecuting = true;
    if (this.getExecuteParams().length != 1) {
        System.out.println("ERROR: Parameters are invalid. Please specify a valid module for update.");
        this.isExecuting = false;
        return;
    }
    String modname = this.getExecuteParams()[0];
    List updates = new UpdateManager().getUpdates();
    if (updates.size() > 0) {
        Properties p, f = null;
        for (int i = 0; i < updates.size(); i++) {
            p = (Properties) updates.get(i);
            if (p.getProperty(InstallerConst.DESCRIPTOR_NAME).equalsIgnoreCase(modname)) {
                f = p;
            }
        }
        if (f == null) {
            System.out.println("No updates found for module [ " + modname + " ].");
        } else {
            System.out.println("Installing update for module [ " + modname + " ]...");
            String url = f.getProperty(InstallerConst.DESCRIPTOR_UPDATE);
            String name = f.getProperty(InstallerConst.DESCRIPTOR_NAME) + "." + f.getProperty(InstallerConst.DESCRIPTOR_VERSION) + InstallerConst.EXTENSION_ARCHIVE;
            if (url != null && url.length() > 6) {
                StreamRequester sr = new StreamRequester(url);
                System.out.println("Downloading update for module [ " + modname + " ] from " + url);
                sr.go();
                try {
                    InstallerEngine.getInstance().install(name, sr.getInputStream(), false);
                    System.out.println("Installation of update for module [ " + modname + " ] successfully finished.");
                    boolean b = Boolean.parseBoolean(f.getProperty(InstallerConst.DESCRIPTOR_RESTART, "false"));
                    if (b) {
                        System.out.println("Module can be used after restarting jAnrufmonitor.");
                    }
                } catch (InstallerException e) {
                    System.out.println("ERROR during installing update for module [ " + modname + " ]: " + e.getMessage());
                }
            } else {
                System.out.println("ERROR: Downloading update for module [ " + modname + " ] from " + url + " failed.");
            }
        }
    } else {
        System.out.println("No update required all modules are up to date...");
    }
    System.out.println();
    this.isExecuting = false;
}
Also used : UpdateManager(de.janrufmonitor.service.update.UpdateManager) List(java.util.List) InstallerException(de.janrufmonitor.framework.installer.InstallerException) Properties(java.util.Properties)

Aggregations

InstallerException (de.janrufmonitor.framework.installer.InstallerException)2 List (java.util.List)2 Properties (java.util.Properties)2 Message (de.janrufmonitor.exception.Message)1 UpdateManager (de.janrufmonitor.service.update.UpdateManager)1 UpdatesPage (de.janrufmonitor.ui.jface.wizards.pages.UpdatesPage)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1