Search in sources :

Example 1 with PluginException

use of org.codelibs.fess.exception.PluginException in project fess by codelibs.

the class PluginHelper method install.

protected void install(final Artifact artifact) {
    final String fileName = artifact.getFileName();
    final String url = artifact.getUrl();
    if (StringUtil.isBlank(url)) {
        throw new PluginException("url is blank: " + artifact.getName());
    }
    if (url.startsWith("http:") || url.startsWith("https:")) {
        try (final CurlResponse response = createCurlRequest(url).execute()) {
            if (response.getHttpStatusCode() != 200) {
                throw new PluginException("HTTP Status " + response.getHttpStatusCode() + " : failed to get the artifact from " + url);
            }
            try (final InputStream in = response.getContentAsStream()) {
                CopyUtil.copy(in, ResourceUtil.getPluginPath(fileName).toFile());
            }
        } catch (final Exception e) {
            throw new PluginException("Failed to install the artifact " + artifact.getName(), e);
        }
    } else {
        try (final InputStream in = new FileInputStream(url)) {
            CopyUtil.copy(in, ResourceUtil.getPluginPath(fileName).toFile());
        } catch (final Exception e) {
            throw new PluginException("Failed to install the artifact " + artifact.getName(), e);
        }
    }
}
Also used : CurlResponse(org.codelibs.curl.CurlResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) PluginException(org.codelibs.fess.exception.PluginException) PluginException(org.codelibs.fess.exception.PluginException) IORuntimeException(org.lastaflute.di.exception.IORuntimeException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) FileInputStream(java.io.FileInputStream)

Example 2 with PluginException

use of org.codelibs.fess.exception.PluginException in project fess by codelibs.

the class PluginHelper method deleteInstalledArtifact.

public void deleteInstalledArtifact(final Artifact artifact) {
    final String fileName = artifact.getFileName();
    final Path jarPath = Paths.get(ResourceUtil.getPluginPath().toString(), fileName);
    if (!Files.exists(jarPath)) {
        throw new PluginException(fileName + " does not exist.");
    }
    switch(artifact.getType()) {
        case THEME:
            ComponentUtil.getThemeHelper().uninstall(artifact);
            uninstall(fileName, jarPath);
            break;
        default:
            uninstall(fileName, jarPath);
            break;
    }
}
Also used : Path(java.nio.file.Path) PluginException(org.codelibs.fess.exception.PluginException)

Example 3 with PluginException

use of org.codelibs.fess.exception.PluginException in project fess by codelibs.

the class PluginHelper method loadArtifactsFromRepository.

protected List<Artifact> loadArtifactsFromRepository(final String url) {
    final String content = getRepositoryContent(url);
    final ObjectMapper objectMapper = new YAMLMapper();
    try {
        @SuppressWarnings("unchecked") final List<Map<?, ?>> result = objectMapper.readValue(content, List.class);
        if (result != null) {
            return result.stream().map(o -> new Artifact((String) o.get("name"), (String) o.get("version"), (String) o.get("url"))).collect(Collectors.toList());
        }
        return Collections.emptyList();
    } catch (final Exception e) {
        throw new PluginException("Failed to access " + url, e);
    }
}
Also used : LoadingCache(com.google.common.cache.LoadingCache) PluginException(org.codelibs.fess.exception.PluginException) CurlRequest(org.codelibs.curl.CurlRequest) IORuntimeException(org.lastaflute.di.exception.IORuntimeException) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) ResourceUtil(org.codelibs.fess.util.ResourceUtil) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) Matcher(java.util.regex.Matcher) ByteArrayInputStream(java.io.ByteArrayInputStream) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) Proxy(java.net.Proxy) Document(org.w3c.dom.Document) Map(java.util.Map) Node(org.w3c.dom.Node) CopyUtil(org.codelibs.core.io.CopyUtil) XMLConstants(javax.xml.XMLConstants) Path(java.nio.file.Path) NodeList(org.w3c.dom.NodeList) Files(java.nio.file.Files) StringUtil(org.codelibs.core.lang.StringUtil) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Collectors(java.util.stream.Collectors) File(java.io.File) Curl(org.codelibs.curl.Curl) TimeUnit(java.util.concurrent.TimeUnit) CacheLoader(com.google.common.cache.CacheLoader) Constants(org.codelibs.fess.crawler.Constants) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Paths(java.nio.file.Paths) ComponentUtil(org.codelibs.fess.util.ComponentUtil) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXException(org.xml.sax.SAXException) Pattern(java.util.regex.Pattern) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) CacheBuilder(com.google.common.cache.CacheBuilder) Comparator(java.util.Comparator) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) CurlResponse(org.codelibs.curl.CurlResponse) InputStream(java.io.InputStream) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) PluginException(org.codelibs.fess.exception.PluginException) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PluginException(org.codelibs.fess.exception.PluginException) IORuntimeException(org.lastaflute.di.exception.IORuntimeException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Aggregations

PluginException (org.codelibs.fess.exception.PluginException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2 CurlResponse (org.codelibs.curl.CurlResponse)2 IORuntimeException (org.lastaflute.di.exception.IORuntimeException)2 SAXException (org.xml.sax.SAXException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 YAMLMapper (com.fasterxml.jackson.dataformat.yaml.YAMLMapper)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 CacheLoader (com.google.common.cache.CacheLoader)1 LoadingCache (com.google.common.cache.LoadingCache)1 File (java.io.File)1 Proxy (java.net.Proxy)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1