Search in sources :

Example 1 with PluginException

use of com.qcadoo.plugin.internal.PluginException in project qcadoo by qcadoo.

the class PluginManagerInstallTest method shouldFailureWithCorruptedPluginOnInstall.

@Test
public void shouldFailureWithCorruptedPluginOnInstall() throws Exception {
    // given
    given(pluginDescriptorParser.parse(file)).willThrow(new PluginException(""));
    given(pluginFileManager.uploadPlugin(pluginArtifact)).willReturn(file);
    given(file.getName()).willReturn("filename");
    // when
    PluginOperationResult pluginOperationResult = pluginManager.installPlugin(pluginArtifact);
    // then
    verify(pluginDao, never()).save(Mockito.any(InternalPlugin.class));
    verify(pluginAccessor, never()).savePlugin(Mockito.any(InternalPlugin.class));
    verify(pluginFileManager).uninstallPlugin("filename");
    assertFalse(pluginOperationResult.isSuccess());
    assertEquals(PluginOperationStatus.CORRUPTED_PLUGIN, pluginOperationResult.getStatus());
}
Also used : PluginException(com.qcadoo.plugin.internal.PluginException) Test(org.junit.Test)

Example 2 with PluginException

use of com.qcadoo.plugin.internal.PluginException in project qcadoo by qcadoo.

the class DefaultPluginDescriptorParser method parse.

@Override
public InternalPlugin parse(final Resource resource) {
    try {
        LOG.info("Parsing descriptor for:" + resource);
        boolean ignoreModules = false;
        URL url = ResourceUtils.extractJarFileURL(resource.getURL());
        return parse(resource.getInputStream(), ignoreModules, FilenameUtils.getName(url.toString()));
    } catch (IOException e) {
        throw new PluginException(e.getMessage(), e);
    } catch (Exception e) {
        throw new PluginException(e.getMessage(), e);
    }
}
Also used : PluginException(com.qcadoo.plugin.internal.PluginException) IOException(java.io.IOException) URL(java.net.URL) PluginException(com.qcadoo.plugin.internal.PluginException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 3 with PluginException

use of com.qcadoo.plugin.internal.PluginException in project qcadoo by qcadoo.

the class DefaultPluginDescriptorParser method loadPlugins.

@Override
public Set<InternalPlugin> loadPlugins() {
    Map<String, InternalPlugin> loadedplugins = new HashMap<String, InternalPlugin>();
    Resource[] resources = pluginDescriptorResolver.getDescriptors();
    for (Resource resource : resources) {
        InternalPlugin plugin = parse(resource);
        if (loadedplugins.containsKey(plugin.getIdentifier())) {
            throw new PluginException("Duplicated plugin identifier: " + plugin.getIdentifier());
        }
        loadedplugins.put(plugin.getIdentifier(), plugin);
    }
    return new HashSet<InternalPlugin>(loadedplugins.values());
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) PluginException(com.qcadoo.plugin.internal.PluginException) Resource(org.springframework.core.io.Resource)

Example 4 with PluginException

use of com.qcadoo.plugin.internal.PluginException in project qcadoo by qcadoo.

the class PluginManagerInstallTest method shouldFailureOnUploadingPluginOnInstall.

@Test
public void shouldFailureOnUploadingPluginOnInstall() throws Exception {
    // given
    given(pluginFileManager.uploadPlugin(pluginArtifact)).willThrow(new PluginException(""));
    // when
    PluginOperationResult pluginOperationResult = pluginManager.installPlugin(pluginArtifact);
    // then
    verify(pluginDao, never()).save(Mockito.any(InternalPlugin.class));
    verify(pluginAccessor, never()).savePlugin(Mockito.any(InternalPlugin.class));
    assertFalse(pluginOperationResult.isSuccess());
    assertEquals(PluginOperationStatus.CANNOT_UPLOAD_PLUGIN, pluginOperationResult.getStatus());
}
Also used : PluginException(com.qcadoo.plugin.internal.PluginException) Test(org.junit.Test)

Example 5 with PluginException

use of com.qcadoo.plugin.internal.PluginException in project qcadoo by qcadoo.

the class DefaultPluginFileManager method uploadPlugin.

@Override
public File uploadPlugin(final PluginArtifact pluginArtifact) {
    InputStream input = pluginArtifact.getInputStream();
    File pluginFile = new File(pluginsTmpPath + getProperty(L_FILE_SEPARATOR) + pluginArtifact.getName());
    try {
        FileUtils.copyInputStreamToFile(input, pluginFile);
    } catch (IOException e) {
        LOG.error("Problem with upload plugin file - " + e.getMessage());
        throw new PluginException(e.getMessage(), e);
    }
    return pluginFile;
}
Also used : InputStream(java.io.InputStream) PluginException(com.qcadoo.plugin.internal.PluginException) IOException(java.io.IOException) File(java.io.File)

Aggregations

PluginException (com.qcadoo.plugin.internal.PluginException)9 IOException (java.io.IOException)4 InternalPlugin (com.qcadoo.plugin.internal.api.InternalPlugin)3 SAXException (org.xml.sax.SAXException)3 File (java.io.File)2 UnknownHostException (java.net.UnknownHostException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Test (org.junit.Test)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 QcadooPluginPlugin (com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin)1 Plugin (com.qcadoo.plugin.api.Plugin)1 PluginDependencyInformation (com.qcadoo.plugin.api.PluginDependencyInformation)1 PluginDependencyResult (com.qcadoo.plugin.api.PluginDependencyResult)1 Builder (com.qcadoo.plugin.internal.DefaultPlugin.Builder)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1